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 / pavan kumar
#include<stdio.h>
int main()
{
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,sum;
printf("Enter the five digit number:");
scanf("%d",&sum);
a=sum%10;
b=sum/10;
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
h=f/10;
printf("sum of the digits:%d",a+c+e+g+h);
}
Is This Answer Correct ? | 7 Yes | 4 No |
Post New Answer View All Answers
Write a program to reverse a string.
Difference between constant pointer and pointer to a constant.
Why calloc is better than malloc?
How does struct work in c?
What's the right way to use errno?
Why does the call char scanf work?
Why c is called free form language?
Subtract Two Number Without Using Subtraction Operator
What are the advantages of union?
how to write optimum code to divide a 50 digit number with a 25 digit number??
a c code by using memory allocation for add ,multiply of sprase matrixes
How is = symbol different from == symbol in c programming?
What is a function simple definition?
Write a program to generate the Fibinocci Series
Differentiate between a structure and a union.