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
In C, What is the #line used for?
What is the explanation for cyclic nature of data types in c?
What is gets() function?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What is the difference between NULL and NUL?
Why void is used in c?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What is indirection? How many levels of pointers can you have?
How does struct work in c?
Why can't I perform arithmetic on a void* pointer?
Explain how can I convert a number to a string?
In which layer of the network datastructure format change is done
Tell me what is the purpose of 'register' keyword in c language?
What is the difference between single charater constant and string constant?