Why my code written in c is giving runtime error while it is running successfully on my computer…
the source code is
#include<stdio.h>
int main()
{
int x,g,a[30],b[30],c[30],t,i,j,key,n;
scanf("%d",&t);
x=0;
g=t;
while(t>0)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
b[i]=a[i];
}
for(j=1;j<n;j++)
{
key=b[j];
i=j-1;
while(i>-1&&b[i]>key)
{
b[i+1]=b[i];
i--;
}
b[i+1]=key;
}
int l,k,p;
c[x]=0;
int max=b[n-1];
k=n-2;
p=1;
while(b[k]==max)
{
k--;
p++;
}
while(1)
{
l=p;
while(k>=0&&l>0)
{
b[k]=max;
k--;
p++;
l--;
}
c[x]++;
if(k==-1)
break;
}
t--;
x++;
}
for(i=0;i<g;i++)
{
printf("%d\n",c[i]);
}
}