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 / haris
Try it. It will seriously work. You would appreciate it.
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
int a;
int b;
int c;
int d;
int e;
int sum;
printf("Please enter a five digit number:\n");
scanf("%d",&x);
a=x%10;
b=(x/10)% 10;
c=(x/100)% 10;
d=(x/1000)%10;
e=(x/10000)%10;
sum=a+b+c+d+e;
printf("\n\nThe sum of all digits is %d.",sum);
getch();
return 0;
}
| Is This Answer Correct ? | 12 Yes | 5 No |
Post New Answer View All Answers
Explain what is the difference between text files and binary files?
What do you mean by invalid pointer arithmetic?
How do you determine the length of a string value that was stored in a variable?
What is the use of pointers in C?
write a c program to find the sum of five entered numbers using an array named number
What is structure data type in c?
Explain the use of #pragma exit?
what is a function method?give example?
Describe the steps to insert data into a singly linked list.
What is c language and why we use it?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
What is a header file?
What are static variables in c?
What is the difference between null pointer and wild pointer?
praagnovation