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 / alex r.
// without loop
// for digit in DEC
#include <stdio.h>
int sum(int digit)
{
if (digit%10 != digit)
return digit%10 + sum(digit/10);
return digit;
}
int main(void)
{
int digit = 25634;
printf("\nSum:%d", sum(digit));
return 0;
}
Is This Answer Correct ? | 15 Yes | 7 No |
Post New Answer View All Answers
Explain how does flowchart help in writing a program?
How can a process change an environment variable in its caller?
What is gets() function?
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
Explain how can I manipulate strings of multibyte characters?
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
Explain indirection?
how to execute a program using if else condition and the output should enter number and the number is odd only...
Why should I use standard library functions instead of writing my own?
What is c mainly used for?
Why is void main used?
What is the function of volatile in c language?
What should malloc() do?
what is use of malloc and calloc?
What is the use of gets and puts?