How to add number using recursion function?

Below code will help you to add number by using recursion function.
#include<stdio.h>
#include<conio.h>
int add(int x);
void main ()
{
int a;
clrscr();
printf(“Enter any number”);
scanf(“%d”,&a);
printf(“%d”,add(a));
getch();
}
int add(int x)
{
if(x==0)
{
return 0;
}
else
return (x%10+add(x/10));
}

After Running program :-

Leave a Reply