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's the difference between constant char *p and char * constant p?
What is the use of typedef in c?
how to make a scientific calculater ?
How arrays can be passed to a user defined function
When is the “void” keyword used in a function?
What are the main characteristics of c language describe the structure of ac program?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
Explain bit masking in c?
What is table lookup in c?
What is the difference between %d and %i?
What is the explanation for cyclic nature of data types in c?
What is the purpose of ftell?
What is a pointer on a pointer in c programming language?
What is multidimensional arrays
What is the purpose of void in c?