當前位置:首頁 » 編程語言 » 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-07-12 19:53:17 瀏覽:46
電腦中的微信聊天記錄在哪裡存儲 發布:2025-07-12 19:47:22 瀏覽:944
蘋果6sp怎麼設置密碼 發布:2025-07-12 19:28:50 瀏覽:547
電視下架緩存的還能看嗎 發布:2025-07-12 19:14:12 瀏覽:444
安卓平板微軟平板和蘋果哪個好 發布:2025-07-12 19:09:37 瀏覽:413
資料庫地區 發布:2025-07-12 19:05:41 瀏覽:395
如何檢查vds腳本 發布:2025-07-12 19:04:24 瀏覽:909
命令行編譯vs2013 發布:2025-07-12 19:01:22 瀏覽:809
c語言輸出所有素數 發布:2025-07-12 19:01:19 瀏覽:659
查電費賬號密碼多少 發布:2025-07-12 18:56:19 瀏覽:545