Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add Digits Of A Number
WhatsApp
Shobana J
8y
7.5
k
0
1
25
Blog
adon.zip
Introduction
In this blog, we will learn how to add the digits of a number.
Software Requirements
Turbo C++ OR C
Programming
#include < stdio.h >
int
main()
{
int
n, t, sum = 0, remainder;
printf(
"Enter an integer\n"
);
scanf(
"%d"
, & n);
t = n;
while
(t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf(
"Sum of digits of %d = %d\n"
, n, sum);
return
0;
}
Explanation
From this above program, we can get the digits of a number. Then, we can add the values given by the user.
Output
Conclusion:
Thus, the program can be printed and executed successfully.
Add Digits
C
Up Next
Armstrong Number In C
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found