plz help!!!MY CODE IS WRONG IDONT KNOW HOW!!

Bytelandian gold coins

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,l,n[10],a,t;
scanf("%d\n",&t);
for(a=0;a<t;a++)
{
scanf("%d",&i);
if(i<12)
{
printf("\n%d",i);
}
else
{
j=i/4;
k=i/3;
l=i/2;
n[a]=j+k+l;
printf("\n%d",n[a]);
}
}
getch();
return 0;
}

conio.h is not a standard file and so is the getch(). Better don’t use them.

Try to use option (in IDE or command line that you are using) that forces the compiler to behave in standard way.

1 Like

#include<stdio.h>

int main()
{
int i,j,k,l,n[10],a,t;
scanf("%d\n",&t);
for(a=0;a<t;a++)
{
scanf("%d",&i);
if(i<12)
{
printf("\n%d",i);
}
else
{
j=i/4;
k=i/3;
l=i/2;
n[a]=j+k+l;
printf("\n%d",n[a]);
}
}

 return 0;

}

still getting wrong answer

Can you give a link to problem statement and your answer. Or post answer in formatted way?

I checked the question. You need to simulate the procedure with coins 4 - n for which your coin value increase and keep a max count. If the value decrease stop processing.

You code simulate the procedure for only 1 iteration. You need to repeat iterations as long as you can increase your value. If value remains same or decreases, stop it.

This looks like an infinitely recursive solution. But using memoization, you can make the things feasible. Please try it yourself, if you find it difficult to grasp, check editorials or others solution. If not understood something, please post.