how remove this error tried everything.... this program is about finding 5 closest number from a array... in main part i simply take array, num and size and passes through the function
void printclosest(int arr[], int x, int n)
{
int diff[30];
int i,j,k,p,a;
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (arr[i] > arr[j])
{
a = arr[i];
arr[i] = arr[j];
arr[j] = a;
}
}
}
for(i=0;i<n;i++)
{
diff[i]=abs(a[i]-x);
}
for (k = 0; k < n; ++k)
{
for (p = k + 1; p < n; ++p)
{
if (diff[k] > diff[p])
{
a = arr[k];
arr[k] = arr[p];
arr[p] = a;
}
}
}
for(i=0;i<5;i++)
{ printf("%d",arr[i]);
}
}
a
声明为int
,但是您尝试在此处将其用作数组:
diff[i]=abs(a[i]-x);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.