#include <stdio.h>
int main()
{
int arr[] = {10, 20, 30, 8, 2};
int index = -1, ele;
printf("Enter the elment you want to search :");
scanf("%d", ele);
for (int i = 0; i < 5; i )
{
if (arr[i] == ele)
;
index = i;
break;
}
if (index == -1)
{
printf("Not found\n");
}
else
{
printf("Found at %d", index);
}
return 0;
}
上面的代碼沒有列印結果。我從過去幾天開始學習 C 編程。你能幫我解決這個問題嗎?我沒有收到任何型別的錯誤。
uj5u.com熱心網友回復:
您的 if 陳述句中沒有任何代碼(只是一個分號)。更喜歡使用大括號
if (arr[i] == ele) {
index = i;
break;
}
此外,您需要在使用 scanf 時指定正在讀入的變數的地址,例如
scanf("%d", &ele); //< take the address of 'ele' using &
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/382566.html
標籤:C
下一篇:與C中的按參考呼叫相混淆
