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 / sriharsha
void main()
{
long int num;
int sum=0,temp;
clrscr();
printf("Enter the numbe\n");
scanf("%ld",&num);
while(num!=0)
{
temp=num%10;
sum=sum+temp;
num=num/10;
}
printf("%d",sum);
getch();
}
| Is This Answer Correct ? | 111 Yes | 42 No |
Post New Answer View All Answers
What is the difference between struct and typedef struct in c?
while initialization of array why we use a[][2] why not a[2][]...?
How can I find the modification date of a file?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
What are header files and what are its uses in C programming?
Tell us two differences between new () and malloc ()?
What is character constants?
Add Two Numbers Without Using the Addition Operator
What is FIFO?
When should volatile modifier be used?
What header files do I need in order to define the standard library functions I use?
How can I find the modification date and time of a file?
Give basis knowledge of web designing ...
What is volatile keyword in c?
What are structural members?