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
What is switch in c?
What is header file definition?
What is advantage of pointer in c?
What the different types of arrays in c?
write a program to copy the string using switch case?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
What happens if header file is included twice?
What language is lisp written in?
what is a function method?give example?
Why is void main used?
What are the different categories of functions in c?
When should a far pointer be used?
What is getch?
What are preprocessor directives?
Between macros and functions,which is better to use and why?