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 how do you view the path?
What is a class c rental property?
What is a protocol in c?
Who is the main contributor in designing the c language after dennis ritchie?
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
In a header file whether functions are declared or defined?
Explain the difference between getch() and getche() in c?
You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.
What are 3 types of structures?
Tell me when is a void pointer used?
Write a code to generate divisors of an integer?
How many loops are there in c?
Is a pointer a kind of array?
Differentiate between #include<...> and #include '...'
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above