Hi I am trying to write a program that generates the prime numbers under a 1000. The program itself works fine until i edit it and try to store the values in an array and then print that array. I know im pretty close to fixing this but i cant seem to find where im going wrong. Any help would be great
Code:
#include <stdio.h>
int main ()
{
int array[1000];
int j=0;
int i = 0; /*assigns value to i*/
printf("The following numbers are prime:\n\n");
while (i < 1000){
int num = 2;
int non = 0;
while ( num < i ){
if ( i%num == 0) { /*true statement means number is not prime */
/*adds 1 to value of i in each time*/
non++;
}
num++;
}
if (non ==0){
scanf("%d",&array[i]);/*prints the prime number for the user */
}
i++;/*adds 1 to value of count*/
}
i=0;
while (i<=1000){
printf("%d",array[i]);
i++;
}
return 0; /*Terminates program*/
}