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
Do you have any idea about the use of "auto" keyword?
Explain what is the benefit of using const for declaring constants?
What is the difference between volatile and const volatile?
Why enum is used in c?
What is array of structure in c programming?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What is header file in c?
Explain what is wrong with this program statement?
Differentiate abs() function from fabs() function.
What is the meaning of && in c?
Are the variables argc and argv are always local to main?
Why c is known as a mother language?
What is variable initialization and why is it important?
Explain how do you determine whether to use a stream function or a low-level function?
What is the use of #define preprocessor in c?