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)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}
//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 an apt answer...
| Is This Answer Correct ? | 11 Yes | 36 No |
Post New Answer View All Answers
What is the purpose of void pointer?
What is the difference between %d and %i?
Function calling procedures? and their differences? Why should one go for Call by Reference?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
What is memory leak in c?
How to create struct variables?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
How to delete a node from linked list w/o using collectons?
Explain what is the advantage of a random access file?
What is indirection?
Explain why C language is procedural?
How can I manipulate individual bits?
What the different types of arrays in c?
When should I declare a function?