
定义fun函数,输入数组求数组中最大元素在数组中的下标,并返回数组中最大元素在数组中的下标
定义fun函数,输入数组求数组中最大元素在数组中的下标,并返回数组中最大元素在数组中的下标对以下函数进行补充...
定义fun函数,输入数组求数组中最大元素在数组中的下标,并返回数组中最大元素在数组中的下标对以下函数进行补充
展开
展开全部
#include<stdio.h>
#include<stdlib.h>
int fun (int arr[], int len) {
int i;
int max,maxIndex;
max = arr[0];
maxIndex = 0;
for (i=0; i<len; i++)
if (arr[i]>max) { /*求最大值、元素编号*/
max = arr[i];
maxIndex = i;
}
return maxIndex;
}
int main (void) {
int a[5] = {876,675,896,101,401};
int index = fun (a, 5);
printf ("index = %d\n", index);
return 0;
}
运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询