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

Explain how does flowchart help in writing a program?

636


How can a process change an environment variable in its caller?

658


What is gets() function?

675


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

648


Explain how can I manipulate strings of multibyte characters?

788






‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

2380


Explain indirection?

652


how to execute a program using if else condition and the output should enter number and the number is odd only...

1663


Why should I use standard library functions instead of writing my own?

679


What is c mainly used for?

603


Why is void main used?

625


What is the function of volatile in c language?

670


What should malloc() do?

653


what is use of malloc and calloc?

1391


What is the use of gets and puts?

608