Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. bool prim(int nr)
  6. {
  7. for(int i = 2; i <= sqrt(nr) ; i++)
  8. if(nr%i == 0)
  9. return false;
  10. return true;
  11. }
  12.  
  13. int nleaprim(int n)
  14. {
  15. int nr=2;
  16. int contor = 0;
  17. while(true)
  18. {
  19. if(prim(nr))
  20. {
  21. cout<< nr << " ";
  22. contor++;
  23. }
  24. if(contor == n)
  25. return nr;
  26. nr++;
  27. }
  28.  
  29. }
  30.  
  31. int main()
  32. {
  33. int n;
  34. cin>>n;
  35. cout<<"al n-lea nr prim este:"<<nleaprim(n);
  36. return 0;
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement