neogz

3s desna

Dec 4th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.    
  6.     int n, s = 0;
  7.  
  8.     do {
  9.         cout << "Unesite jedan cijeli pozitivan broj: ";
  10.         cin >> n;
  11.     } while (n < 0);
  12.  
  13.     while (n>0)
  14.     {
  15.         n /= 100;
  16.         s += n % 10;
  17.         n /= 1000;
  18.         s += n % 10;
  19.        
  20.     }
  21.  
  22.     cout << s;
  23.  
  24.  
  25.     system("pause>nul");
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment