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 / aryan garg
#include<stdio.h>
int main()
{
int n,d1,d2,d3,d4,d5,s;
printf("enter a five digit no");
scanf("%d",&n);
d5=n%10;n=n/10;
d4=n%10;n=n/10;
d3=n%10;n=n/10;
d2=n%10;n=n/10;
d1=n%10;
s=d1+d2+d3+d4+d5;
printf("sum of the digits of number is : %d",s);
return 0;
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Why is %d used in c?
What is sizeof return in c?
What is FIFO?
What is pointer to pointer in c with example?
What is a buffer in c?
Is javascript based on c?
Explain the difference between malloc() and calloc() function?
any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above
What are control structures? What are the different types?
Which programming language is best for getting job 2020?
What are the functions to open and close the file in c language?
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
Are comments included during the compilation stage and placed in the EXE file as well?
how should functions be apportioned among source files?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.