重生之影视大明星:在a数组中查找与x 值相同的元素的所在位置,用指针实现。请填空

来源:百度文库 编辑:高考问答 时间:2024/05/03 10:18:09
main()
{int a[6],x,i;
printf("\nInput 5 numbers:");
for (i=1; i<=5; i++) scanf("%d",a+i); /* 读数到a[1]…a[5] */
printf("\nInput x:");
scanf("%d", &x);
*a=x; i=5; /* 将x存入a[0]中 */
while (x!=*(a+i))
【 】;
if (【 】) printf("%5d's position is: %4d\n",x,i);
else printf("%5d Not been found!\n",x);
}
程序运行结果:
Input 5 numbers: 1 3 5 7 9
Input x: 3
3's position is 2