Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add Digits Of A Number
WhatsApp
Shobana J
8y
7.7
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
People also reading
Membership not found