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
Can we assign string to char pointer?
Write a program to print all permutations of a given string.
What is the difference between int main and void main?
What is time null in c?
What is pivot in c?
What is null pointer in c?
can any one provide me the notes of data structure for ignou cs-62 paper
Is c object oriented?
What does 3 periods mean in texting?
Write the control statements in C language
How can I run c program?
Difference between Function to pointer and pointer to function
What is the use of parallelize in spark?
I have seen function declarations that look like this
what are non standard function in c