Cannot figure out the problem

I cannot figure out what’s wrong in my code. I am a newbie to the programming world. Help would really be appreciated.

This is the code I wrote for the problem RECIPE :

#include <stdio.h>
int main()
{
	int t, n, i;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		int a[n], flag=0, min=1001;
		for(i=0;i<n;i++)
		scanf("%d", &a[i]);
		for(i=0;i<n;i++)
		if(a[i]<min)
        min=a[i];
		for(i=0;i<n;i++)
		if(a[i]%min != 0)
        {
            flag=1;
            break;
        }
		if(flag==0)
		{
            for(i=0;i<n;i++)
            printf("%d ", a[i]/min);
            printf("\n");
		}
		else
		{
            for(i=0;i<n;i++)
            printf("%d ", a[i]);
            printf("\n");
		}
	}
	return 0;
}

Your approach is wrong and thus it will be wrong answer for the problem. Try to understand the problem then you will find the right approach.

The right approach is to-

1-Find the gcd(Greatest Common divisor) of the array
2-Divide each element by gcd of array
3-print the array

Try to implement above approach and you code will be AC.

Thank you. It worked ! :smiley: :smiley: