Advertisement
SergeyPGUTI

6.1.6

Oct 24th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  int SumOfDigits (int n)
  6. {
  7.     int k=0,sum=0;
  8.     while (n>0)
  9.     {
  10.         k=n%10;
  11.         sum+=k;
  12.         n/=10;
  13.     }
  14.     return sum;
  15. }
  16.  
  17. int main()
  18.  
  19. {
  20.     int n;
  21.     cin>>n;
  22.     cout<<SumOfDigits(n);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement