Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

coins :using recursion

$
0
0

this is my program but i am unable to fix the bug. Can anybody help me figure this out.

#include<stdio.h>
int fun(int x);
int main()
{
int test,n,y;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
y=fun(n);
printf("%d\n",y);
}
return 0;
}
int fun(int x)
{
int a,b,c,d;
a=x/4;
b=x/3;
c=x/2;
d=a+b+c;
if(x>=d)
return x;
else
{
a=fun(a);
b=fun(b);
c=fun(c);
}
return (a+b+c);
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



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