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
What is a double c?
What does %p mean?
How can I write a function analogous to scanf?
Can true be a variable name in c?
What is the function of this pointer?
explain what is a newline escape sequence?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
Can the curly brackets { } be used to enclose a single line of code?
What are the similarities between c and c++?
Why is it that not all header files are declared in every C program?
What is function prototype in c with example?
What are the different file extensions involved when programming in C?
What are identifiers and keywords in c?
we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above
What is %d used for?