課程
/后端開發(fā)
/C
/C語言入門
6.6
2016-11-17
源自:C語言入門 6-5
正在回答
#include <stdio.h>
int getIndex(int arr[5],int value)
{
? ? int i;
? ? int index;
? ? for(i=0;i<5;i++)
? ? {
? ? ? ?/* 請完善數(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; ? ?
舉報
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
1 回答C語言入門6-8
1 回答C語言入門2.4章節(jié)
2 回答C語言6-3節(jié)練習(xí)題
1 回答c語言%C
3 回答c語言第一個編程
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-11-18
#include <stdio.h>
int getIndex(int arr[5],int value)
{
? ? int i;
? ? int index;
? ? for(i=0;i<5;i++)
? ? {
? ? ? ?/* 請完善數(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; ? ?
}