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
Explain what is wrong with this program statement?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
What is scope of variable in c?
Explain the process of converting a Tree into a Binary Tree.
Dont ansi function prototypes render lint obsolete?
What are the 5 data types?
The statement, int(*x[]) () what does in indicate?
What is the purpose of sprintf?
Is javascript based on c?
What are the uses of null pointers?
How is a null pointer different from a dangling pointer?
How important is structure in life?
What is the heap?
How will you find a duplicate number in a array without negating the nos ?
What is the code for 3 questions and answer check in VisualBasic.Net?