Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

1. //program to print the sum of n prime nos. #include<iostream.h> #include<conio.h> void main() { clrscr(); int *p,chk !,n,s !

,div,i; //*p for storing n prime nos. //chk is to check if no. is prime cout<<"#n please enter the value of n$"; cin>>n; do { if(n< !) { cout<<"#n the value of n should %e greater than &ero#n"; cout<<"#n enter the value of n again$"; cin>>n; ' '(hile(n< !); p ne( int)n*; cout<<"#n enter the "<<n<<" prime nos.$#n"; for(i !;i<n;i++) { cout<<" "; cin>>p)i*; do { if(p)i*<,)//checking if no. is < , as , is lo(est prime no. { cout<<"#n the no. should %e greater than -"; cout<<"#n enter again$#n"; cout<<" "; cin>>p)i*; ' '(hile(p)i*<,); do { chk !; for(div ,;div<p)i*;div++) if(p)i*.div !)//checking if no. is prime { chk++; %reak; ' if(chk !)s+ p)i*;//adding the nos. if the/ are prime else { cout<<"#n the no. entered is not prime"; cout<<"#n enter the no. again$#n"; cout<<" "; cin>>p)i*;

-); ' cout<<"#n press an/ ke/"; getch(); clrscr(); cout<<"#n the nos. to %e added are$#n"; for(i !;i<n;i++) cout<<" "<<p)i*<<endl; //displa/ing nos.entered that are prime cout<<"#n the sum of the n prime nos. are$"<<s; cout<<"#n press an/ ke/"; getch(); ' 0utput$

' '(hile(chk

You might also like