GerexD

gy13_9

Jan 15th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. //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!
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a,b,x,i,n,p,o=0;
  9.  
  10. cin>>a;
  11. cin>>b;
  12.  
  13. if (a<b)
  14. {
  15. x=a;
  16. a=b;
  17. b=x;
  18.  
  19. }
  20.  
  21. for(i=b;i<=a;i++)
  22. {
  23. p=1;
  24.  
  25.  
  26. for(n=2;n<=sqrt(i);n++)
  27. if(i%n==0) p=0;
  28.  
  29. if(p==1 && n!=2)
  30. {
  31. cout<<i<<endl;
  32. o=o+i;
  33. }
  34. }
  35. cout<<"A primek osszege-->"<<o<<endl;
  36.  
  37.  
  38.  
  39.  
  40.  
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment