首页 > 试题广场 >

编写一个函数,返回一个double数组中存储的最大数值的索引

[问答题]

编写一个函数,返回一个double数组中存储的最大数值的索引,并在一个简单程序中测试这个函数。

推荐
#include <stdio.h>
#define WIDTH 6
int max(float [], int );
int main(void)
{
 float array[] = {4.3, 5.3, 2.6, 9.2, 2.8, 3.6};
 printf("The max numnber's index is: %d\n",max( array, WIDTH));
 return 0;
} 
int max(float a[], int n)
{
 int i,max;
 for (i = 1, max = 0; i < n; i++)
 if (a[max] < a[i])
 max = i;
 return max;
}

发表于 2018-05-05 21:46:34 回复(0)