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

void main()
{
long int num;
int sum=0,temp;
clrscr();
printf("Enter the numbe\n");
scanf("%ld",&num);
while(num!=0)
{
temp=num%10;
sum=sum+temp;
num=num/10;
}
printf("%d",sum);
getch();
}


Is This Answer Correct ?    111 Yes 42 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we change the value of constant variable in c?

564


What does the function toupper() do?

643


Can include files be nested?

617


Is main an identifier in c?

590


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

893






How can you return multiple values from a function?

620


What are pointers in C? Give an example where to illustrate their significance.

737


What library is sizeof in c?

557


What are high level languages like C and FORTRAN also known as?

668


the question is that what you have been doing all these periods (one year gap)

1610


What are 3 types of structures?

582


what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

1422


How do you print only part of a string?

602


Why does notstrcat(string, "!");Work?

632


what type of questions arrive in interview over c programming?

1543