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


Please Help Members By Posting Answers For Below Questions

Write a program to reverse a string.

631


Difference between constant pointer and pointer to a constant.

607


Why calloc is better than malloc?

565


How does struct work in c?

602


What's the right way to use errno?

615






Why does the call char scanf work?

611


Why c is called free form language?

565


Subtract Two Number Without Using Subtraction Operator

348


What are the advantages of union?

623


how to write optimum code to divide a 50 digit number with a 25 digit number??

2745


a c code by using memory allocation for add ,multiply of sprase matrixes

2294


How is = symbol different from == symbol in c programming?

607


What is a function simple definition?

608


Write a program to generate the Fibinocci Series

655


Differentiate between a structure and a union.

756