0% found this document useful (0 votes)
9 views2 pages

program To Print The Sum of N Prime Nos

This C++ program allows a user to input the value of n and then enter n prime numbers. It then checks if each number entered is prime and sums only the prime numbers. The output displays the prime numbers entered and the total sum.

Uploaded by

satyag24
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

program To Print The Sum of N Prime Nos

This C++ program allows a user to input the value of n and then enter n prime numbers. It then checks if each number entered is prime and sums only the prime numbers. The output displays the prime numbers entered and the total sum.

Uploaded by

satyag24
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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