Quantcast
Viewing latest article 3
Browse Latest Browse All 3

Recursive a+b function

I am practising recursion and have written the small code for summing a+b as below:

#include <stdio.h>int b=6;static int cnt;void main(void){    int a=9,sum;    sum=succ(a);    printf("Sum returned : %d\n",sum);}int succ(x){    cnt++;    return(cnt<=b ? succ(x+1) : x++);}

I am getting the results fine using this. Can anyone suggest optimization or better code for this? I also want to understand how stacking happens in this case for variables cnt and x. Are they stacking in pairs like 0-9, 1-10 ,2-11,3-12 ,4-13, then at last when cnt is 5 it return x from the post-increment return?


Viewing latest article 3
Browse Latest Browse All 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>