本題要求從輸入的N個整數中查找給定的X。如果找到,輸出X的位置(從0開始數);如果沒有找到,輸出“Not Found”。
輸入格式:
輸入在第一行中給出兩個正整數N(≤20)和X,第二行給出N個整數。數字均不超過長整型,其間以空格分隔。
給出一個整數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
7-6 查找整數 (10 分)
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main()
{int n,x,i;int c[10010];scanf("%d%d",&n,&x);for(i=0;i<n;i++){scanf("%d",&c[i]);if(c[i]==x)break;}if(i==n)printf("Not Found\n");elseprintf("%d\n",i);return 0;
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态