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 / aryan garg
#include<stdio.h>
int main()
{
int n,d1,d2,d3,d4,d5,s;
printf("enter a five digit no");
scanf("%d",&n);
d5=n%10;n=n/10;
d4=n%10;n=n/10;
d3=n%10;n=n/10;
d2=n%10;n=n/10;
d1=n%10;
s=d1+d2+d3+d4+d5;
printf("sum of the digits of number is : %d",s);
return 0;
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is array of structure in c?
What is variables in c?
When we use void main and int main?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
Explain how do you print an address?
Write a code of a general series where the next element is the sum of last k terms.
What does a function declared as pascal do differently?
What are the 4 types of unions?
write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.
program for reversing a selected line word by word when multiple lines are given without using strrev
write a c program in such a way that if we enter the today date the output should be next day's date.
Explain data types & how many data types supported by c?
What are the advantages of using Unions?
What is a constant?
What is strcpy() function?