Introduction
- In this blog, we will learn how to add the digits of a number.
Software Requirements
- Turbo C++ OR C
Programming
Explanation
- #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;
- }
- 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.

kalu singh raoPosted Jul 15, 2016, 10:07 AM
Nice...
kalu singh raoPosted Jul 15, 2016, 10:07 AM
Nice...