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
What is multidimensional arrays
Explain the use of #pragma exit?
What are pointers? What are different types of pointers?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
C language questions for civil engineering
What are global variables?
Why n++ execute faster than n+1 ?
using for loop sum 2 number of any 4 digit number in c language
Is javascript based on c?
What do you mean by c what are the main characteristics of c language?
What is the purpose of 'register' keyword in c language?
Where is volatile variable stored?
What is non linear data structure in c?
What is the purpose of realloc()?
Create a simple code fragment that will swap the values of two variables num1 and num2.