About us

C Program for finding the sum of digits in the given number using recursion

C Program for finding the sum of digits in the given number using recursion

c-program-finding-sum-of-digits-given-number

#include<stdio.h>
#include<conio.h>
int sum(long int a);

void main()
{
 long int num;
 clrscr();
 printf("Enter any number for find sum of digits in it\n");
 scanf("%ld",&num);
 printf("Sum of digits in %ld is %d",num,sum(num));
 getch();
}

int sum(long int n)
{
 if(n>0)
  return((n%10)+sum(n/10));
 else
  return 0;
}


OUTPUT

c-program-finding-sum-of-digits-given-number


------------------------------------------------------------------------------------------------------------

You can also visit:-