Advertisement
IvanB61

Zadatak 4.

Jan 30th, 2023
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     int zbir = 0;
  10.     while (n != 0){
  11.         zbir += (n % 10);
  12.         n = n / 10;
  13.     }
  14.     cout << zbir << endl;
  15.     return 0;
  16. }
  17.  
  18. // Na ovaj nacin mi je bilo jednostavnije, ali moze i preko for petlje a i ovako:
  19. //    int j = n % 10;
  20. //    int d = n % 100;
  21. //    int s = n % 1000;
  22. //    zbir = j + d + s;
  23. //    cout << z << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement