[ create a new paste ] login | about

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

salvador@conclase.net - C++, pasted on Nov 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Sumar los dígitos de un número
// (C) 2009 Con Clase
// Salvador Pozo

#include <iostream>

using namespace std;

int SumaDigitos(int);

int main() {
    cout << 32890123 << ": " << SumaDigitos(32890123) << endl;
    return 0;
}

int SumaDigitos(int n) {
    if(n < 10) return n;
    return n%10+SumaDigitos(n/10);
}


Output:
1
32890123: 28


Create a new paste based on this one


Comments: