Catherine_zhilin

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 int search(int key,int a[], int length);//函数声明 
 6 int main() {
 7     int  a[]={1,2,3,4,5,6,7,8,9,0,13,68,99};
 8     int x,b;
 9     printf("请输入您要找的数\n");
10     scanf("%d",&x);
11     b=search(x,a,sizeof(a)/sizeof(a[0]));
12     if(b==-1){
13         printf("没有您要找的数");
14     } 
15     else{
16         printf("你要找的数在%d",b);
17     } 
18     return 0;
19 }
20 int search(int key,int a[],int length){
21     int m=-1,i;
22     for(i=0;i<length;i++){
23     
24     if(key==a[i]){
25         m=i+1;
26         break;
27     }    
28     }
29     return m;
30 }

测试结果:

 

posted on 2019-01-15 15:45  kkkshiki  阅读(357)  评论(0编辑  收藏  举报