C program to find sum of all digits
To find sum of digits in c program first we have to accept number from user and modulus that number with 10 (this will give us last digit of original number).
Store reminder in one variable and then add reminder in result variable. (keep default value of result variable as 0).
Now to remove last digit from original number divide it by 10 and store it in same variable.
Carry same steps with remaining number and we will get our result.
#include<stdio.h>
int main()
{
int x,rsl=0,y;
printf("Enter any number : ");
scanf("%d",&x);
while(x>0)
{
y=x%10;
rsl=rsl+y;
x=x/10;
}
printf("Result is = %d",rsl);
return 0;
}
Output :
Enter any number : 1234
Result is = 10
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author
Looking forward to reading more. Great blog article. Want more. Lucine Bob Brose