What have I done wrong here? Again syntax or something else?
Code:#include <stdio.h> int main() { int array[47]; /*Sets array to 47*/ int primeNumber = 1; /* declare and initialise the starting point of the search for primes */ int count=0; while(primeNumber < 230) { int loopGuard = 2; /* initialise the loop guard */ int numDivisors = 0; /* variable representing the number of divisors a number has */ while(loopGuard < primeNumber) /* continue to perform the statements while the loopGuard is less than or equal to the current number (loopGuard) */ { if(primeNumber % loopGuard == 0) /* if the given number is divisable by the current number (loopGuard) */ { numDivisors =numDivisors + 1; /* increase our count of the number of divisors */ } /* always increment the loopGuard variable */ loopGuard = loopGuard + 1; } /* if there are no divisors for the number it must be prime */ if(numDivisors == 0){ array[count]=primeNumber; } count++; /*Count adds one*/ primeNumber = primeNumber + 1; /* increment the loop guard i.e. test if the next number is prime */ } count=0; while (count < 47) /*While count less than 10*/ { printf("%d ", array[count]); /*Prints numbers according to the position list[1], [2], [3] etc*/ count++; /*Count adds one*/ } return 0; }



3Likes
LinkBack URL
About LinkBacks



