c语言题 编写一个函数

求思路!编写一个函数,返回储存在 int 类型数组中的最大值;编写一个函数,返回储
存在 double 类型数组中最大值的下标;编写一个函数,把 double 类型数组中的
数据倒序排列。在一个简单的程序中调用并测试这三个函数。

没什么思路,就是站照着你这个题目打就行。想要源代码@静渊隐者

供参考:

#include <stdio.h>
#define N 10
int max_arr(int a[], int n)//返回储存在 int 类型数组中的最大值
{
    int i, max;
    for (i=0, max=a[i]; i < n; i++)
        if (max < a[i]) max = a[i];
    return max;
}
int maxpos_arr(double a[], int n)//返回储存在 double 类型数组中最大值的下标
{
    int i, pos;
    for (i=0,pos=0; i < n; i++)
        if (a[pos] < a[i]) pos = i;
    return pos;
}
void rever_arr(double a[], int n)//把 double 类型数组中的数据倒序排列
{
    int i;
    double t;
    for (i=0; i < n / 2; i++)
    {
        t=a[i];
        a[i]=a[n-1-i];
        a[n-1-i]=t;
    }
}
int main()
{
    int a[N]={2,1,5,3,6,9,7,10,23,11},i;
    double b[N]={4.2,3.5,2.2,9.6,5.7,10.2,3.9,4.1,8.6,7.0};
    printf("max=%d\n",max_arr(a,N));
    printf("maxpos=%d\n", maxpos_arr(b,N));
    rever_arr(b,N);
    for (i=0; i < N; i++)
        printf("%6.1f", b[i]);
    return 0;
}

供参考!谢谢!

img

#include <stdio.h>

//函数一  返回最大值
int max(int *a, int n)
{
    int max = a[0];
    for (int i = 0; i < n; i++)
    {
        if (a[i] > max)
            max = a[i];
    }
    return max;
}

//函数二  返回最大值下标
int maxIndex(double *a, int n)
{
    double max = a[0];
    int j = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] > max)
        {
            max = a[i];
            j = i;
        }
    }
    return j;
}

//函数三 把数组倒数
void reversArr(double *a, int n)
{
    int mid = n / 2;
    double tmp;

    for (int i = 0, j = n - 1; i < mid; i++, j--)
    {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
}

int main(int argc, char *argv[])
{
    double a[] = {1.1, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9};
    int b[] = {1, 2, 3, 4, 5};
    puts("输出原数组a:");
    for (int i = 0; i < 8; i++)
    {
        printf("%.1lf ", a[i]);
    }

    puts("\n输出原数组b:");
    for (int i = 0; i < 5; i++)
    {
        printf("%d ", b[i]);
    }

    puts("");
    printf("数组b中最大值:%d\n", max(b, 5));

    printf("数组a最大值的下标:%d\n", maxIndex(a, 8));

    reversArr(a, 8);

    puts("数组a翻转后:");
    for (int i = 0; i < 8; i++)
    {
        printf("%.1lf ", a[i]);
    }
    puts("");
    return 0;
}