TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Add Digits Of A Number
Shobana J
Jul 15, 2016
7.4
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, I'm going to explain how to add the digits of a number.
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
Next Recommended Reading
Armstrong Number In C