Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- //9. Adott egy [a,b] intervallum. Írjuk ki az intervallumból a prímeket csökkenő sorrendben és határozzuk meg ezek összegét is!
- using namespace std;
- int main()
- {
- int a,b,x,i,n,p,o=0;
- cin>>a;
- cin>>b;
- if (a<b)
- {
- x=a;
- a=b;
- b=x;
- }
- for(i=b;i<=a;i++)
- {
- p=1;
- for(n=2;n<=sqrt(i);n++)
- if(i%n==0) p=0;
- if(p==1 && n!=2)
- {
- cout<<i<<endl;
- o=o+i;
- }
- }
- cout<<"A primek osszege-->"<<o<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment