mirror of
https://github.com/tiennm99/KTLT.git
synced 2026-06-18 05:26:50 +00:00
32 lines
403 B
C++
32 lines
403 B
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
int result(int n);
|
|
|
|
int main()
|
|
{
|
|
int n = 12345;
|
|
cout << result(n);
|
|
return 0;
|
|
}
|
|
|
|
int result(int n)
|
|
{
|
|
if (n == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
if (n%2 == 1)
|
|
{
|
|
return n%10 + result(n/10);
|
|
}
|
|
else
|
|
{
|
|
return result(n/10);
|
|
}
|
|
}
|
|
}
|