本题要求从输入的N个整数中查找给定的X。如果找到,输出X的位置(从0开始数);如果没有找到,输出“Not Found”。
输入格式:
输入在第1行中给出2个正整数N(<=20)和X,第2行给出N个整数。数字均不超过长整型,其间以空格分隔。
输出格式:
在一行中输出X的位置,或者“Not Found”。
输入样例1:
5 7
3 5 7 1 9
输出样例1:
2
输入样例2:
5 7
3 5 8 1 9
输出样例2:
Not Found
#include<stdio.h>
int main(){
int a[21];
int n,x,count=0;
scanf("%d %d",&n,&x);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++){
if(x!=a[i])
count++;
else
printf("%d",i);
}
if(count==n)
printf("Not Found");
return 0;
}