Search This Blog

Translate

write a c program to find the sum of digits of a number using recursive function


write a c program to find the sum of digits of a number using recursive function

write a c program to find the sum of digits of a number using recursion


#include
#include

int rev(int);
int sum=0,r, count=0;

void main()
{ int n,re;
clrscr();
  printf("\n Enter number  :");
scanf("%d",&n);
  re= rev(n);

  printf("\n %d \n count= %d ",re,count);
   getch();
}

int rev(int n)
{
  if(n)
  {
   r=n%10;
   printf("\n %d",r);
   count++;
   sum=sum*10+r;
   rev(n/10);
  }
return sum;
}

C Program example List

Google+ Badge