int array[100], i;
for(i = 0; i < 100; i++)
{
scanf("%d", &array[i]);
}
This is giving me following warning
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]
Edit
Actual code:
#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
}
So based on your actual code:
Fix:
scanf("%d",&n);
^ Use ampersand sign
You need to use address of variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With