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 / aha na
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,sum=0;
clrscr();
printf("\n enter a number",i);
scanf("%d",&i);
while(i<=0)
{
j=i%10;
sum=sum+j;
i=i/10;
}
printf("\n the sum of the digits
are:%d\n");
getch();
}
| Is This Answer Correct ? | 14 Yes | 30 No |
Post New Answer View All Answers
Differentiate abs() function from fabs() function.
How do you list files in a directory?
Explain 'far' and 'near' pointers in c.
What is a ternary operator in c?
What are global variables and how do you declare them?
How is pointer initialized in c?
What is an array? What the different types of arrays in c?
What is string constants?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
What is register variable in c language?
What is the difference between char array and char pointer?
How will you find a duplicate number in a array without negating the nos ?
What are the different data types in C?
What is the difference between printf and scanf in c?