if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')
Answer Posted / jegadeesh
#include<stdio.h>
void main()
{
int i,j;
scanf("%d",&i);
if(i>9)
{
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}
else
{
printf("The sum of digit is ",i);
}
}
//the above will print result as 6 if given as 12345 since
1+2+3+4+5=15 and proceeding 1+5 we get as 6.....
is this answer u are looking...
| Is This Answer Correct ? | 9 Yes | 4 No |
Post New Answer View All Answers
Explain can the sizeof operator be used to tell the size of an array passed to a function?
Explain what is the difference between text files and binary files?
Can we assign integer value to char in c?
What is f'n in math?
code for find determinent of amatrix
What is the data segment that is followed by c?
How to declare pointer variables?
how to capitalise first letter of each word in a given string?
What are the differences between new and malloc in C?
When we use void main and int main?
What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?
How can I recover the file name given an open stream?
Can we change the value of #define in c?
Why c is called free form language?
How do you initialize pointer variables?