查找某一个数

Description
输入一个从小到大排列的有序数列(长度小于100),在此数列中查找某一个数x,若找到,输出相应下标,否则,输出”Not Found".

Input
先输入要查找的数x和n, 再输入n个有序数。

Output
输出x所在位置下标或"Not Found"

Sample Input
2 8 -2 2 3 8 9 20 25 67
5 7 -2 2 3 8 9 20 25
Sample Output
1
Not Found

#include<stdio.h>
int main()
{
int n,x,a[100],i,s,j;
while(scanf("%d",&x)!=EOF)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
s=-1;
for(j=0;j<n;j++)
{
if(a[j]x)
{
printf("%d\n",j);
s=j;
break;
}
}
if(s
-1)
printf(“Not Found\n”);
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/z2431435/article/details/83832324