Advertisement
EnsarMeskovic

Slozen broj rastaviti na proste faktore

Jan 23rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void prostifaktor(int);
  5.  
  6. void main()
  7. {
  8.     int broj;
  9.  
  10.     cout << "Unesite broj : ";
  11.     cin >> broj;
  12.  
  13.     cout << broj << " = ";
  14.     prostifaktor(broj);
  15.  
  16.     system("pause>0");
  17. }
  18. void prostifaktor(int br)
  19. {
  20.     int i = 2;
  21.     while (br != 0) {
  22.         if (br%i == 0) {
  23.             br /= i;
  24.             if (br == 1)
  25.                 cout << i << endl;
  26.             else
  27.                 cout << i << "*";
  28.         }
  29.         else
  30.             i++;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement