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 / haris
Try it. It will seriously work. You would appreciate it.
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
int a;
int b;
int c;
int d;
int e;
int sum;
printf("Please enter a five digit number:\n");
scanf("%d",&x);
a=x%10;
b=(x/10)% 10;
c=(x/100)% 10;
d=(x/1000)%10;
e=(x/10000)%10;
sum=a+b+c+d+e;
printf("\n\nThe sum of all digits is %d.",sum);
getch();
return 0;
}
Is This Answer Correct ? | 12 Yes | 5 No |
Post New Answer View All Answers
I have seen function declarations that look like this
What does 3 mean in texting?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
The statement, int(*x[]) () what does in indicate?
How was c created?
Explain what are header files and explain what are its uses in c programming?
When we use void main and int main?
How are portions of a program disabled in demo versions?
I need testPalindrome and removeSpace
#include
I came across some code that puts a (void) cast before each call to printf. Why?
Can the curly brackets { } be used to enclose a single line of code?
What is maximum size of array in c?
Explain how can I right-justify a string?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.