Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool provjera(int);
  5.  
  6. int main() {
  7. int brN;
  8. cout << "Unesite neki broj n: ";
  9. cin >> brN; // savrseni brojevi: 6, 28, 496 (source: wikipedia)
  10. if (provjera(brN) == true){
  11. cout << "Broj " << "je savrsen!" << endl;
  12. }
  13. else cout << "no";
  14.  
  15. system("pause>0");
  16. return 0;
  17. }
  18.  
  19. bool provjera(int broj) {
  20.  
  21. int sum = 0;
  22. for (int i = 1; i< broj; i++) {
  23. if (broj%i == 0)
  24. sum += i;
  25. }
  26.  
  27. if (sum == broj){
  28. return true;
  29. }
  30. else
  31. return false;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement