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

Do you have any idea about the use of "auto" keyword?

656


Do you know the difference between exit() and _exit() function in c?

603


What is an auto keyword in c?

631


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

642


What is a node in c?

541






How is a macro different from a function?

648


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

734


What is static memory allocation? Explain

625


What is the significance of an algorithm to C programming?

584


Tell me the use of bit field in c language?

616


Explain what is page thrashing?

603


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

4973


What is the scope of static variables in c language?

622


What is adt in c programming?

598


How do you do dynamic memory allocation in C applications?

622