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

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:600
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:892
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:586
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:771
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:690
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1016
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:261
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:120
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:809
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:719