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
What is difference between array and structure in c?
What Is The Difference Between Null And Void Pointer?
What is the modulus operator?
Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent
Explain how can you check to see whether a symbol is defined?
Explain zero based addressing.
What happens if a header file is included twice?
What is volatile keyword in c?
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
Write a program to print factorial of given number using recursion?
What's the right way to use errno?
Are there any problems with performing mathematical operations on different variable types?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
In which language linux is written?
What are derived data types in c?