示例代码:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n = 0 , key = 0 , count = -1;
int i = 0 ;
int *num;
scanf("%d",&n);
num = (int *)malloc(sizeof(int)*n);
for (i = 0 ; i < n ; i ++)
{
scanf("%d",&num[i]);
}
scanf("%d",&key);
for (i = 0 ; i < n ; i ++)
{
if (num[i] == key)
{
count = i + 1;
break;
}
}
printf("%d",count);
free(num);
num = NULL;
return 0;
}