I am not looking into the algorithm. This is the working code (Using visual studio):
#include <stdio.h>
#include <math.h>
#define N 300
void displayPrime (bool checkPrime);
bool checkPrime (int num);
bool is_prime[N+1];
void displayPrime (bool check)
{
int I;
for(I=1; I<N; I++)
{
checkPrime(is_prime[I]);
if(is_prime[I]==true)
{
printf("%d\n", I);
}
else if(is_prime[I]==false)
{
printf("");
}
}
}
bool checkPrime (int num)
{
int I;
is_prime[1]=false;
for(I=2; I*I<=N; I++)
{
for(num=I; num<=N/num; num=num*I)
{
is_prime[num]=false;
}
return(is_prime[I]);
}
}
void main()
{
displayPrime(is_prime);
getchar();
}
I have changed these things:
- You cannot declare a variable twice.
- Every variable can be used within scope
{}
- A function called should be declared before you call.
TRUE
should betrue
andFALSE
should befalse
.- use return type in main function.
Anyway Sieve
has a lot of good implementation. Try them out.