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
Is array a primitive data type in c?
What is a good data structure to use for storing lines of text?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
When a c file is executed there are many files that are automatically opened what are they files?
What is string length in c?
What is the easiest sorting method to use?
write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
write a program to generate address labels using structures?
How do you generate random numbers in C?
using only #include
Is a pointer a kind of array?
An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?
Explain how do you convert strings to numbers in c?