[ create a new paste ] login | about

Link: http://codepad.org/bwpGuJF8    [ raw code | output | fork ]

C++, pasted on Sep 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main()
{
  int num;
  int sum = 0;

  cout << "Please type any non-negative integer: ";
  cin >> num;

  while ( num > 0 ) {
    sum += num % 10;
    num /= 10;
  }

  cout << "The sum of the digits of " << num << " is " << sum << "\n";

  return 0;
}


Output:
1
Please type any non-negative integer: The sum of the digits of 0 is 0


Create a new paste based on this one


Comments: