Advertisement
Guest User

armstrongov broj

a guest
Aug 30th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. bool suma(int n)
  5. {
  6.     int sum = 0;
  7.     int temp = 0;
  8.     int n1 = n;
  9.     while (n1 > 0)
  10.     {
  11.         temp=n1% 10;
  12.         n1 /= 10;
  13.         sum+= temp*temp*temp;
  14.         temp = 0;
  15.     }
  16.     if (sum==n)
  17.         return true;
  18.     else
  19.         return false;
  20. }
  21.  
  22. void ispis(int n)
  23. {
  24.         if (suma(n) == true)
  25.         cout << "armstrongovi brojevi " << n<< endl;
  26.        
  27.    
  28. }
  29. int main()
  30. {
  31.     int n;
  32.     cout << "unesite neki broj "<< endl;
  33.     cin >> n;
  34.  
  35.     if (n <200)
  36.     {
  37.         for (int i = 1; i < n; i++)
  38.             ispis(i);
  39.     }
  40.  
  41.     else
  42.         cout << "broj veci od 200 " << endl;
  43.        
  44.  
  45.     system("pause");
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement