Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int zbir = 0;
- while (n != 0){
- zbir += (n % 10);
- n = n / 10;
- }
- cout << zbir << endl;
- return 0;
- }
- // Na ovaj nacin mi je bilo jednostavnije, ali moze i preko for petlje a i ovako:
- // int j = n % 10;
- // int d = n % 100;
- // int s = n % 1000;
- // zbir = j + d + s;
- // cout << z << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement