#include <stdio.h>
void main()
{
long num, temp, digit, sum = 0;
printf(“Enter the number\n”);
scanf(“%ld”, &num);
temp = num;
while(num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}
printf(“Given number =%ld\n”, temp);
printf(“Sum of the digits %ld =%ld\n”, temp, sum);
} /* End of main()*/
/*—————————————
Enter the number
123456
Given number =123456
Sum of the digits 123456 =21
—————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept an integer and reverse it
- C program to accept a string and find the sum of all digits present in the string
- C program to find the sum of first 50 natural numbers using for loop
- C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
