#include<math.h>
void main()
{
long int num,sum = 0,dig;
clrscr();
printf(“nnt ENTER A NUMBER…: “);
scanf(“%ld”,&num);
while(num>0)
{
dig = num % 10;
sum = sum + dig;
num = num / 10;
}
printf(“nt SUM OF DIGITS IS…: %ld”, sum);
getch();
}
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept an integer find the sum of the digits in it
- C program to find the sum of first 50 natural numbers using for loop
- C program to accept a string and find the sum of all digits present in the string
- C program to read a matrix A (MxN) and to find the following using functions a) Sum of the elements of each row b) Sum of the elements of each column c) Find the sum of all the elements of the matrix Output the computed results with suitable headings
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
