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
given post order,in order construct the corresponding binary tree
Are pointers integers in c?
How can this be legal c?
Write a program to find factorial of a number using recursive function.
What are the 5 data types?
Explain two-dimensional array.
What is c programing language?
How can a process change an environment variable in its caller?
Is c still used?
Explain About fork()?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What do you mean by recursion in c?
What is define c?
Is there a built-in function in C that can be used for sorting data?