getting desired output but when submitting it says wrong answer for problem code RECIPE,what to do ? following is my code

#include <stdio.h>
#include <stdlib.h>
int gcd(int a,int b)
{
int temp;
if(b>a)
{
temp=b;
b=a;
a=temp;
}
if(b==0)
return a;
else
return gcd(b,a%b);
}

int main()
{ int t,n,k,i;
   scanf("%d",&t);
   while(t--)
    {
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++)
       {
        scanf("%d",&a[i]);
        }
         k=gcd(a[0],a[1]);
        for(i=2;i<n;i++){
        k=gcd(k,a[i]);
        if(k==1)
        {
            for(i=0;i<n;i++)
                printf("%d ",a[i]);
        }
        else
        {
            for(i=0;i<n;i++)
                printf("%d ",a[i]/k);
        }
        }
        if(n==2)
        {printf("%d %d",a[0]/k,a[1]/k);}
        else if(n==1)
        {
            printf("%d",a[0]);
        }
        printf("\n");
    }
    return 0;
}

can you please give your solution link. It’s difficult to read.

Try this test case and think what’s wrong with your code

4 3 15 9 2

Hey @gigabyte,

I think your approach to solving the problem is correct but the implementation is wrong. you need first find the gcd of all the numbers present in the array after that print the output. your program find gcd upto ith place and after that, it divides it by the number.

for a better explanation, you can see my


[1]

Hope this helps!
 


  [1]: https://www.codechef.com/viewsolution/15031745

Your program computes gcd upto 3rd element of array.

//