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
Explain what happens if you free a pointer twice?
Add Two Numbers Without Using the Addition Operator
Tell me with an example the self-referential structure?
What is memory leak in c?
How can you allocate arrays or structures bigger than 64K?
Explain what is gets() function?
What is non linear data structure in c?
What is static volatile in c?
What is a stream in c programming?
What is the heap in c?
What is the advantage of using #define to declare a constant?
What is function prototype in c with example?
There seem to be a few missing operators ..
define string ?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays