Advertisement
adnanj

Zadatak 3 - Grupa B - PR1 - 25.01.2016. god.

Jan 25th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool trivijalan(int);
  5. int djelitelji(int);
  6.  
  7.  
  8. int main()
  9. {
  10.     int broj;
  11.     cout << "Unesite broj: ";
  12.     cin >> broj;
  13.  
  14.     if (trivijalan(broj))
  15.         cout << "Broj je prost." << endl;
  16.     else
  17.         cout << "Broj je slozen i ima " << djelitelji(broj) << " djelitelja." << endl;
  18.  
  19.     system("pause>0");
  20.     return 0;
  21. }
  22.  
  23.  
  24. bool trivijalan(int broj)
  25. {
  26.     for (int i = 2; i <= broj / 2; i++)
  27.         if (broj % i == 0)
  28.             return false;
  29.     return true;
  30. }
  31.  
  32. int djelitelji(int broj)
  33. {
  34.     int brojDjelitelja = 0;
  35.     for (int i = 2; i <= broj / 2; i++)
  36.         if (broj % i == 0)
  37.             brojDjelitelja++;
  38.     return brojDjelitelja;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement