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 / richa

main()
{
int num , sum=0 ;
printf(" enter 5 digit no. " );
scanf(" %d " , num);
while (num!=0)
{ sum+=num%10;
num=num/10;
}
printf("sum is = %d " , sum );
getch();
}

Is This Answer Correct ?    24 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a constant pointer in C

638


What is derived datatype in c?

610


Why is c faster?

572


What is the basic structure of c?

536


Explain how do you sort filenames in a directory?

584






What is a rvalue?

723


What is structure padding in c?

600


What is union and structure?

553


Is boolean a datatype in c?

523


Explain bit masking in c?

605


What is volatile variable how do you declare it?

541


Why we use int main and void main?

522


What is break statement?

606


What is #ifdef ? What is its application?

615


What are global variables and explain how do you declare them?

543