ValerianBenchea

Suma cifrelor

Jan 15th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, s=0, c;
  8.     cin>>n;
  9.     while(n!=0)
  10.     {
  11.         c=n%10;
  12.         s=s+c;
  13.         n=n/10;
  14.     }
  15.     cout<<s;
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment