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
How many data structures are there in c?
What is the difference between test design and test case design?
Differentiate Source Codes from Object Codes
What is the basic structure of c?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
What is void main () in c?
Explain how can a program be made to print the name of a source file where an error occurs?
What are the Advantages of using macro
What is hungarian notation? Is it worthwhile?
using only #include
Why is it important to memset a variable, immediately after allocating memory to it ?
What are the 5 types of inheritance in c ++?
What is the purpose of 'register' keyword?
If null and 0 are equivalent as null pointer constants, which should I use?
What is type qualifiers?