當前位置:首頁 » 編程語言 » c語言查找數組元素

c語言查找數組元素

發布時間: 2023-03-15 07:19:31

⑴ C語言實現整型數組中查找指定元素的函數

#include<stdio.h>
int search(int a[], int n, int searchValue) {
int i;
for(i=0; i<n; i++) if(a[i]==searchValue) return i;
return -1;
}
int main() {
int i;
int a[10],find,idx;
for(i=0; i<10; i++) {
printf("Input a[%d]:",i);
scanf("%d",&a[i]);
}
printf("Input searchValue:");
scanf("%d",&find);
idx=search(a,10,find);
if(idx!=-1) printf("pos=%d",idx);
else printf("not found");
}

熱點內容
打包sql資料庫 發布:2025-07-12 16:19:27 瀏覽:794
php日誌查看 發布:2025-07-12 16:12:10 瀏覽:212
ftp目錄映射為本地盤符 發布:2025-07-12 16:06:59 瀏覽:643
nas存儲百科 發布:2025-07-12 16:03:17 瀏覽:124
python的sort函數 發布:2025-07-12 15:53:21 瀏覽:48
ensp伺服器怎麼設置web根目錄 發布:2025-07-12 15:47:56 瀏覽:284
安卓怎麼設置二卡發信息 發布:2025-07-12 15:43:50 瀏覽:743
如何看到無線密碼 發布:2025-07-12 15:43:13 瀏覽:675
好網址可緩存 發布:2025-07-12 15:36:07 瀏覽:252
centos安裝php52 發布:2025-07-12 15:14:19 瀏覽:298