Hi, I'm having problems with this C program. Whenever I run it, it doesn't print anything. The program is supposed to compute and display all the prime numbers from 1 - 300 using the sieve of eratosthenes and using arrays (passing arrays to functions). Whenever i run it the compiler compiles it, shows a window for half a second, and closes again. Here is what I've done so far:
[code=c]
/* This program uses the Sieve of Eratosthenes to
* find all the prime numbers in the range of 1 - 300.
*/
#include <stdio.h>
#include "genlib.h"
#include "math.h"
#define maxNums 300
bool is_Prime(bool flag[]);
main()
{
bool flag[maxNums];
is_Prime(flag);
getchar();
}
bool is_Prime(bool flag[])
{
int x, y;
bool TRUE, FALSE;
for(x=2;x<=sqrt (maxNums);x++)
{
y=x*x;
while(y<=maxNum s)
{
flag[x*y] = FALSE;
y++;
}
}
y=0;
while(y<=maxNum s)
{
if(flag[y]!=FALSE)flag[y] = TRUE;
y++;
}
for(y=1;y<=maxN ums;y++)
{
if(flag[y] = TRUE)printf("%d \n", flag[y]);
}
}
[/code]
Help would be greatly appreciated. Thanks!
[code=c]
/* This program uses the Sieve of Eratosthenes to
* find all the prime numbers in the range of 1 - 300.
*/
#include <stdio.h>
#include "genlib.h"
#include "math.h"
#define maxNums 300
bool is_Prime(bool flag[]);
main()
{
bool flag[maxNums];
is_Prime(flag);
getchar();
}
bool is_Prime(bool flag[])
{
int x, y;
bool TRUE, FALSE;
for(x=2;x<=sqrt (maxNums);x++)
{
y=x*x;
while(y<=maxNum s)
{
flag[x*y] = FALSE;
y++;
}
}
y=0;
while(y<=maxNum s)
{
if(flag[y]!=FALSE)flag[y] = TRUE;
y++;
}
for(y=1;y<=maxN ums;y++)
{
if(flag[y] = TRUE)printf("%d \n", flag[y]);
}
}
[/code]
Help would be greatly appreciated. Thanks!
Comment