WRONG ANSWER :TONYFOOD ,PLEASE GUIDE

#include <stdio.h>

int main() {
int t,i,j,a[100],avg,sum=0,count=0,tot=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{scanf("%d",&a[i]);
sum=sum+a[i];
}
avg=sum/3;
for(i=0;i<t;i++)
{if(a[i]==avg)
count++;
a[i]==0;
}
for(i=0;i<t;i++)
{
for(j=i;j<t;j++)
{ tot=tot+a[j];
if(tot==avg)
{count++;}}}
if(count==3)
printf(“Yes\n%d”,avg);
else printf(“No\n”);
return 0;
}

//WHERE IS MY CODE WRONG???

Its very hard to read your code, use external code sharing sites or markup to share your code instead of directly copy pasting it.

Anyway refer to this link for TONYFOOD: https://www.geeksforgeeks.org/partition-set-k-subsets-equal-sum/ (set k = 3)

Here is his well-indented code - https://ideone.com/63YoPy

1 Like