write a program to sum of its digit with using control
structure or with out using loop. for ex: let the number is
25634 then answer will be=2+5+6+3+4=20

Answer Posted / lalabs

// assume that num is non-negative.

int sum_digits_recursive ( int num )
{
if ( num == 0 ) return 0;
return (num % 10 + sum_digits_recursive ( num / 10 ));
}

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are structure members?

601


What is unsigned int in c?

565


How can I read in an object file and jump to locations in it?

583


Explain goto?

722


Explain what is a pragma?

596






what is ur strangth & weekness

1828


What is the code in while loop that returns the output of given code?

1347


Why c language?

654


What is sizeof in c?

577


Which is better pointer or array?

606


Explain what are bus errors, memory faults, and core dumps?

796


Explain low-order bytes.

625


the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

646


What is the purpose of type declarations?

683


Where static variables are stored in c?

593