manhaeve5
Gebruiker
- Lid geworden
- 9 jan 2007
- Berichten
- 276
Dit is hier m'n code:
is er nog een manier om dit te versnellen?
Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
bool checkpriem(int* getal);
int main()
{
int aantal;
ofstream output;
output.open("priemgetallen.txt");
cout<<"Alle priemgetallen tot ";
cin>>aantal;cin.ignore();
output<<2<<endl<<3<<endl<<5<<endl<<7<<endl;
for(int a=2;a<aantal;a++)
{
if(a%2!=0&&a%3!=0&&a%5!=0&&a%7!=0){
if(checkpriem(&a)==true)
output<<a<<endl;
}
}
output.close();
cout<<"Klaar"<<endl;
cin.get();
return 0;
}
inline bool checkpriem(int* getal)
{
bool priem=true;
for(int a=2;a<*getal;a++)
{
if(*getal%a==0)
{
priem=false;
break;
}
}
return priem;
}