Hey I was wonderin if someone could help me with my program I am having trouble on how to get it to work properly...so this is what I have so far
The instrcutions wereCode:#include <iostream> using namespace std; int main() { const int numberOfPrimesToFind=10; int discoveredPrimes[numberOfPrimesToFind]; discoveredPrimes[0]=2; int noOfdiscoveredPrimes=1; int numberUnderTest=3; // the remainder bool isDivisible =0; int i; for(i=0;i<noOfdiscoveredPrimes;i++){ isDivisible = !(numberUnderTest%discoveredPrimes[i]);//! is an invert (just the opposite) if (isDivisible) break; } if(!isDivisible){ discoveredPrimes[i]=numberUnderTest; noOfdiscoveredPrimes++; } for (i=0; i<noOfdiscoveredPrimes; i++){ cout<<"Prime Numberis divisible by "<<i<<"= "<<discoveredPrimes[i]<<endl; } (i NEED HELP ON THIS PART BELOW) while (i<=numberOfPrimesToFind; i++;)) { cout<<"Number of Primes"<<i<<" ="<<numberUnderTest<<endl; } return 0; }
Write a program to find the first 10 prime numbers.
Hint: Prime numbers are numbers that can not be divided by
any other prime number other than 1.
Hint: Once you have determined that a number is prime,
store it in an array to try it for future tests.
Can someone help me with the while loop?? to make the numbers prime



LinkBack URL
About LinkBacks


