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
Do you know the use of fflush() function?
Is boolean a datatype in c?
What does 3 mean in texting?
What are the advantages and disadvantages of a heap?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
What are two dimensional arrays alternatively called as?
Differentiate call by value and call by reference?
why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above
What is the difference between struct and union in C?
Why do we use main function?
What is a program flowchart?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What are the data types present in c?
Explain built-in function?
Is a pointer a kind of array?