Long f (n)
{
If (n!=0)
Return (n % 10 + f (n/10));
The else
return 0;
}
Int main ()
{
Long n=1234567890;
Printf (" % ld \ n ", f (n));
return 0;
}
The answer to the C program is 45, but I don't understand how operation, have a great god help me solve
CodePudding user response:
Recursion, equivalent to the n=1234567890 individual bits togetherCodePudding user response:
Recursive function, n=1234567890, each number, the sum of 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9=45. Return (n % 10 + f (n/10)); N % each number 10, f (10) n/n under a number,CodePudding user response:
Fn (123456789)===& gt;9 + fn (12345678)
9 + 8 + fn (1234567);
9 + 8 + 7 (123456);
9 + 8 +... 1;
CodePudding user response: