• 2021-04-14
    中国大学MOOC:"下面程序的功能是从键盘输入10个整数,用函数编程实现计算其最大值和最小值,并互换它们所在数组中的位置。程序运行结果如下:Input n(n<=10):10↙Input 10 Numbers:1 4 3 0 –2 6 7 2 9 -1 ↙Exchange results: 1 4 3 0 9 6 7 2 -2 -1按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include
    void ReadData(int a[], int n);
    void PrintData(int a[], int n);
    void MaxMinExchang(int a[], int n);
    void Swap(int *x, int *y);
    int main()
    {
    int a[10], n;
    printf("Input n(n<=10):");
    scanf("%d", &n);
    printf("Input %d numbers:", n);
    ReadData(a, n);
    MaxMinExchang(a, n);
    printf("Exchange results:");
    PrintData(a, n);
    return 0;
    }

    /* 函数功能:输入数组a的n个元素值 */
    void ReadData(int a[], int n)
    {
    int i;
    for (i=0; i maxValue)
    {
    maxValue = _______;
    maxPos = ____;
    }
    if (a[i] < minValue)
    {
    minValue = a[i];
    minPos = i;
    }
    }
    Swap(________________);
    }

    /* 函数功能:两整数值互换 */
    void Swap(int *x, int *y)
    {
    int ________;
    temp = *x;
    _________;

    *y = temp;
    }";
  • 举一反三