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 / joy
#include<stdio.h>
main ()
{
int num, a, b,c,d,e, sum;
printf ("Enter the five digit number : ");
scanf ("%d", &num);
e = num % 10;
d = (num / 10)% 10;
c = (num / 100)% 10;
b = (num / 1000)% 10;
a = (num / 10000)% 10;
sum= a+b+c+d+e;
printf ("The sum of the digits is: %d", sum);
}
| Is This Answer Correct ? | 25 Yes | 5 No |
Post New Answer View All Answers
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
Why does not c have an exponentiation operator?
How old is c programming language?
Is null always defined as 0(zero)?
What is d'n in c?
Who invented bcpl language?
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
What is the benefit of using an enum rather than a #define constant?
Why is this loop always executing once?
What does #pragma once mean?
Explain the advantages of using macro in c language?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
Can true be a variable name in c?
What are header files? What are their uses?
What is cohesion and coupling in c?