Sum of Two numbers using recursion function in C
How to add two number using recursion function in C?
Solution:
#include <stdio.h>
int main(int
argc, char *argv[]){
int a,b;
scanf("%d%d",&a,&b);
printf("%d",sum(a,b));
return 0;
}
int sum(int a,int b){
static int s=0;
if(b > 0){
s++;
sum(a,b-1);
}
else if(a>0){
s++;
sum(a-1,b);
}
return s;
}
No comments