求問(wèn)大佬,哪里錯(cuò)了?
#include <stdio.h>
int getIndex(int arr[5],int value)
{
? ? int i;
? ? int index;
? ? for(i=0;i<5;i++)
? ? {
? ? ? ?/* 請(qǐng)完善數(shù)組查詢功能 */
? ? ? if(arr[i]==value)
? ? ? ? ? {
? ? ? ?index = i ;
? ? ? ?break;
? ? }
? ? else
? ? {
? ? ? ? index=-1;
}
?return index;
? ? }
int main()
{
? ? int arr[5]={3,12,9,8,6};
? ? int value = 8;
? ? int index = getIndex(arr,value); //這里應(yīng)該傳什么參數(shù)呢?
? ? if(index!=-1)
? ? {
? ? ? ? printf("%d在數(shù)組中存在,下標(biāo)為:%d\n",value,index);? ? ? ? ? ? ?
? ? }
? ? else
? ? {
? ? ? ? printf("%d在數(shù)組中不存在。\n",value);? ??
? ? }
? ? return 0;? ??
}
2019-08-26
?index=-1;
}
?return index;
? ? }
index=-1; ?應(yīng)該是后面有兩個(gè) ?} ? ?你缺了一個(gè)
補(bǔ)上就運(yùn)行成功了,求采納