In: Computer Science
#include<iostream>
using namespace std;
// a function that returns true if the input integer x is prime,
false otherwise
bool isPrime(int x){
if(x < 2)
return false; // primes
start from 2, so x is not prime
// check for any possible division part from 1 or
itself
for(int n = 2; n < x; n++)
if(x % n == 0)
return false; // x is not prime
return true; // x
is prime
}
int main(){
int N = 10; // the number of primes required
int primesArray[N]; // array to hold the prime
numbers
int x = 0; // the starting guess
of a prime
int i = 0; // the counter form primes
while(i < N){
if(isPrime(x)){ // call
the function to check if this x is prime
primesArray[i] =
x; // store x as a prime
cout<<primesArray[i]<<endl; // show
contents of array in console
i++;
// count this prime
}
x++; // next number to check if
prime
}
return 0;
}
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~