In the previous post we learn about What is palindrome number and How to write a program for palindrome number.
In this post we will learn how to write a program for sum of digits in C.
Sum of digits means addition of two or more than two numbers for example number 456 will be 15.
456
4+5+6=15
In this post we will learn how to write a program for sum of digits in C.
Sum of digits means addition of two or more than two numbers for example number 456 will be 15.
456
4+5+6=15
Program for Sum of digits:
#include <stdio.h> #include <conio.h> int main() { int n, num, rem, sum=0; clrscr(); printf("Enter number"); scanf("%d",&num); while(num>0) { rem=num%10; sum=sum+rem; num=num/10; } printf("sum of digit=%d",sum); getch(); }
Output:
Enter number: 456
Sum of digit: 15
0 comments:
Post a Comment