#include <stdio.h>
#include <conio.h>
int sum1 (int a);
int main()
{
int num, result;
printf("Enter the number: ");
scanf("%d", &num);
result = sum1(num);
printf("Sum of all digits in %d is %d\n", num, result);
getch();
return 0;
}
int sum1 (int num)
{
if (num != 0)
{
return (num % 10 + sum1 (num / 10));
}
else
{
return 0;
}
}
Enter the number: 24547
Sum of all digits in 24547 is 22
--------------------------------
Process exited after 8.261 seconds with return value 0
Press any key to continue . . .