第一次总结(1)

-1 查找整数 (10 分)

本题要求从输入的N个整数中查找给定的X。如果找到,输出X的位置(从0开始数);如果没有找到,输出“Not Found”。

# include<stdio.h>
int main (void)
{
   int i,N,x,count=0;
     scanf ("%d %d",&N,&x);
     int a[N];     
     for (i=0;i<N;i++)
  {
    scanf("%d",&a[i]);
    if (x==a[i])
    {
      printf ("%d",i);
      count++;
    }
  }
  if (count==0){
    printf("Not Found");
  }
  return 0;
}

发现在for语句中scanf("%d",&a[N])错误应该把a[N]改为a[i]

猜你喜欢

转载自www.cnblogs.com/xulongfei/p/10466018.html