Question #5459

write a program in c++ that display the first 20 prime number using while loop.

Expert's answer

# include<iostream.h>

# include<conio.h>

//calculation

int isprime(int valuex)

{

int x,j;

x=1;

& for (j=2 ; j<valuex; j++)

{ if ((valuex%j)==0) x=0; }

& if(x!=0) return 1;

& else return 0;

}

void main(){

int i, n;

i=0;

n=0;

while (n<20){

& if (isprime(i)==1) { cout<<i<<"\n"; n++; }

& i++;

}

getch();

}

## Comments

## Leave a comment