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

Is c high or low level?

773


What is methods in c?

820


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

903


What are pointers? What are different types of pointers?

808


What is the difference between void main and main in c?

851


What is a memory leak? How to avoid it?

863


What is difference between structure and union with example?

800


What is p in text message?

727


which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

2871


Explain the difference between #include "..." And #include <...> In c?

785


given post order,in order construct the corresponding binary tree

2525


Tell me when would you use a pointer to a function?

803


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

839


What is a c token and types of c tokens?

810


Can you please explain the difference between exit() and _exit() function?

809