amermo

N-ti prost broj

Feb 25th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. bool prost(int broj)
  4. {
  5.     int counter(0);
  6.     for(int i = 1; i<=broj; i++)
  7.     {
  8.         if(broj % i == 0)
  9.             counter++;
  10.     }
  11.     if(counter == 2)
  12.         return true;
  13.     return false;
  14. }
  15.  
  16. int nti_prost(int indeks)
  17. {
  18.     int counter(0), pocetni(2);
  19.     while(counter < indeks)
  20.     {
  21.         if(prost(pocetni))
  22.             counter++;
  23.         pocetni++;
  24.     }
  25.     return pocetni-1;
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     int indeks;
  32.     std::cout << "Unesite indeks: " << std::endl;
  33.     std::cin >> indeks;
  34.     std::cout << "Nti prosti broj je: " << nti_prost(indeks);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment