當前位置:首頁 » 編程語言 » 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");
}

熱點內容
我的世界公益伺服器 發布:2025-09-16 02:26:18 瀏覽:829
我的世界對戰伺服器2021 發布:2025-09-16 02:13:05 瀏覽:740
蘋果店教編程 發布:2025-09-16 01:55:33 瀏覽:532
linux安全狗 發布:2025-09-16 01:51:18 瀏覽:638
bash腳本格式 發布:2025-09-16 01:42:02 瀏覽:505
ftp訪問錯誤代碼550 發布:2025-09-16 01:32:21 瀏覽:439
打lol什麼配置要求 發布:2025-09-16 01:32:14 瀏覽:60
香港績點演算法 發布:2025-09-16 01:25:33 瀏覽:935
集合順序存儲 發布:2025-09-16 01:17:31 瀏覽:583
安卓如何開啟應用數據 發布:2025-09-16 00:51:14 瀏覽:585