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


Please Help Members By Posting Answers For Below Questions

What is switch in c?

632


What is header file definition?

556


What is advantage of pointer in c?

679


What the different types of arrays in c?

602


write a program to copy the string using switch case?

2383






How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

575


What happens if header file is included twice?

635


What language is lisp written in?

599


what is a function method?give example?

1902


Why is void main used?

602


What are the different categories of functions in c?

631


When should a far pointer be used?

587


What is getch?

616


What are preprocessor directives?

660


Between macros and functions,which is better to use and why?

1557