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 math functions are available for integers? For floating point?
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
What is a struct c#?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
What is the difference between class and object in c?
What does a pointer variable always consist of?
What language is windows 1.0 written?
Explain how can I avoid the abort, retry, fail messages?
Write a code to generate a series where the next element is the sum of last k terms.
What are the types of i/o functions?
Explain what is gets() function?
using only #include
Can a local variable be volatile in c?
What is the size of empty structure in c?
What is a loop?