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 / areeb ahmed khan
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e;
int digit,number,sum;
printf("\n\n\n");
printf("Enter a five-digit number :");
scanf("%d",&number);
digit=number%10;
a=digit;
number=number/10;
digit=number%10;
b=digit;
number=number/10;
digit=number%10;
c=digit;
number=number/10;
digit=number%10;
d=digit;
number=number/10;
digit=number%10;
e=digit;
sum=a+b+c+d+e;
printf("\nThe sum of five-digit number is : %d",sum);
getch();
}
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
Explain how can I remove the trailing spaces from a string?
Why doesn't C support function overloading?
Why do we use return in c?
When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.
What are the types of bitwise operator?
What is meant by errors and debugging?
How many parameters should a function have?
Explain what are linked list?
What is static volatile in c?
What is a macro in c preprocessor?
What does nil mean in c?
Is c call by value?
What is this infamous null pointer, anyway?
Explain what is the difference between the expression '++a' and 'a++'?
How do I swap bytes?