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 / aryan garg
#include<stdio.h>
int main()
{
int n,d1,d2,d3,d4,d5,s;
printf("enter a five digit no");
scanf("%d",&n);
d5=n%10;n=n/10;
d4=n%10;n=n/10;
d3=n%10;n=n/10;
d2=n%10;n=n/10;
d1=n%10;
s=d1+d2+d3+d4+d5;
printf("sum of the digits of number is : %d",s);
return 0;
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Why we write conio h in c?
write a proram to reverse the string using switch case?
How can I change their mode to binary?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
Why do we use namespace feature?
Explain how do you list a file’s date and time?
how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.
Explain the use of function toupper() with and example code?
write an algorithm to display a square matrix.
Differentiate fundamental data types and derived data types in C.
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
What is indirection in c?
How are 16- and 32-bit numbers stored?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above