https://www.codechef.com/problems/RECIPE

The following problem had the easiest solution but I don’t want to just copy and paste someone’s code as I’ve already coded a logic which might have some error.

The logic works with the test examples but fails when I submit it. Please review my logic and help me out.

int main(void) {

// your code goes here

int arr[N],t,n,i,sum,temp;

scanf("%d",&t);

while(t–)

{

scanf("%d",&n);

sum=0;

for(i=0;i<n;i++)

{

scanf("%d",&arr[i]);

sum+=arr[i];

}

temp=arr[0];

//finding GCD

while(sum!=temp)

{

if(sum > temp)

sum -= temp;

else

temp -= sum;

}

// printing…

for(i=0;i<n;i++)

{

if(arr[i]%sum==0)

{

arr[i]=arr[i]/sum;

}

printf("%d “,arr[i]);

}

printf(”\n");

}

return 0;

}