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 / md osama
#include<stdio.h>
#include<conio.h>
void main()
{
int d1,d2,d3,d4,d5,sum;
long num;
clrscr();
printf("enter the five digit number:");
scanf("%ld",&num);
d1=(num%10);
d2=(num%100-num%10)/10;
d3=(num%1000-num%100)/100;
d4=(num%10000-num%1000)/1000;
d5=(num-num%10000)/10000;
sum=d1+d2+d3+d4+d5;
printf("\n the sum of the digit is:%d",sum);
}
| Is This Answer Correct ? | 12 Yes | 1 No |
Post New Answer View All Answers
the question is that what you have been doing all these periods (one year gap)
What are disadvantages of C language.
Is it better to use a macro or a function?
Write a program to generate random numbers in c?
How do I round numbers?
Explain built-in function?
What is indirection in c?
What happens if a header file is included twice?
Does c have enums?
Why do we use header files in c?
What is the difference between the expression “++a” and “a++”?
Is the exit() function same as the return statement? Explain.
What is the use of putchar function?
about c language
What is pointer to pointer in c with example?