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
How can you find out how much memory is available?
What are the complete rules for header file searching?
What is the use of getch ()?
Mention four important string handling functions in c languages .
If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.
When should you not use a type cast?
What are header files and what are its uses in C programming?
hi, which software companys will take,if d candidate's % is jst 55%?
What is volatile keyword in c?
State the difference between realloc and free.
Write a c program to build a heap method using Pointer to function and pointer to structure ?
What is difference between && and & in c?
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
how many errors in c explain deply
Is c is a procedural language?