SelinD

ex130

May 16th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int prim(int n)
  5. {
  6. int d=2;
  7. if(n<2) return 0;
  8. for(d=2;d<=n/2;d++)
  9. {
  10. if(n%d==0)
  11. return 0;
  12. }
  13. return 1;
  14. }
  15.  
  16. int main()
  17. {
  18. int x,y,k,cate=0,i;
  19. cin>>x>>y>>k;
  20. for(i=x; i<=y; i++)
  21. {
  22. if(prim(i)==1 && cate<=k)
  23. {
  24. cout<<i<<" ";
  25. cate++;
  26. }
  27. }
  28. if(cate!=0)
  29. cout<<endl<<"s-au gasit mai putine nr prime:"<<cate<<" ";
  30. }
Add Comment
Please, Sign In to add comment