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 a good data structure to use for storing lines of text?
What is the difference between ‘g’ and “g” in C?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
What is this pointer in c plus plus?
What is adt in c programming?
How can I remove the leading spaces from a string?
What is the difference between the = symbol and == symbol?
In which layer of the network datastructure format change is done
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
Tell us the use of fflush() function in c language?
What is volatile keyword in c?
What is pass by reference in c?
how to build a exercise findig min number of e heap with list imlemented?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What’s the special use of UNIONS?