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


Please Help Members By Posting Answers For Below Questions

How can I change the size of the dynamically allocated array?

882


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1367


What is chain pointer in c?

773


What will be your course of action for a push operation?

843


How do you view the path?

880


Is it cc or c in a letter?

758


Why do we need arrays in c?

815


What header files do I need in order to define the standard library functions I use?

741


What is meant by inheritance?

841


how do you programme Carrier Sense Multiple Access

1718


How can I read and write comma-delimited text?

834


What does %c mean in c?

844


What are derived data types in c?

801


Why do we need volatile in c?

932


Is it better to use malloc() or calloc()?

832