int array[100], i;
for(i = 0; i < 100; i++)
{
scanf("%d", &array[i]);
}
这给了我以下警告
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]
编辑
实际代码:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int array[100], n, j, ctr = 0, flag = 0;
#define FIX(i) ((array[i]==i)?1:0)
#define CHECK(i,num) ((array[i]==num)&&(array[num]==i)?1:0)
scanf("%d", n);
printf("\n");
for (j = 0; j < n; j++)
{
scanf("%d", &array[j]);
if (array[j] >= n)
{
printf("out of range\n");
return;
}
else
{
if (FIX(j) == 1)
ctr++;
else if ((array[j] < j) && ((CHECK(j,array[j])) == 1) && (flag == 0))
{
ctr = ctr + 2;
flag = 1;
}
} //end if
} //end loop
}