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
What are nested functions in c?
Difference between strcpy() and memcpy() function?
What is the benefit of using const for declaring constants?
int i=10; printf("%d %d %d", i, i=20, i);
What is pre-emptive data structure and explain it with example?
What are the header files used in c language?
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
Explain how can you be sure that a program follows the ansi c standard?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
How can I read in an object file and jump to locations in it?
Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.
How can you find the exact size of a data type in c?
Explain how can I manipulate strings of multibyte characters?
What is calloc()?
I need previous papers of CSC.......plz help out by posting them.......