Answer to Question #5459 in C++ for zuhaib abbasi

Question #5459
write a program in c++ that display the first 20 prime number using while loop.
1
Expert's answer
2011-12-08T09:14:28-0500

# 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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS