Code:
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
int numarray[100];// create space for array
int i, top, remainder, numberOfPrimes, prime; Remainder, not reminder
int minusONE;//pointer for array
//Has to be moved out of the two nested loops for finding primes.
printf("pls enter top limit:");
scanf("%d",&top);
prime = 1;
numberOfPrimes = 0;
do
{
for(minusONE = (top / 2); minusONE > 1; minusONE--) //Top / 2 is not the best, sqrt top is, but it's way better than top - 1
{
remainder = top % minusONE;
printf("\n%d / %d remainder is %d", top, minusONE, remainder);
if(remainder==0) //it's not a prime number, so stop processing it.
{
prime = 0;
break; //break out of the for loop.
}
} //end of for
// if prime == 1 at this point, you have a prime number. Add this if statement, and put the prime number, into the array.
if(blah blah blah)
{
array of primes[numberOfPrimes++] = top;
prime = 1;
}while(--top > 1);
//print up the arrray of primes
for(i = 0; i < numberOfPrimes; i++)
print array of primes[i];
system("pause");
return 0;
}
this is the code that i did.. i only manage to get the remainder..
after which i have to store thse that rem!=0 into my array as prime number
then i have to print out those number and sum up.