Enter 10 integers, the smallest number is exchanged with the first number, and the largest number is exchanged with the last number

#include<stdio.h>
int main()
{
    void inputf(int*, int);
    void work(int*, int);
    void outputf(int*, int);
    int a[10];
    inputf(a, 10);
    work(a, 10);
    outputf(a, 10);
    return 0;
}
void inputf(int p[], int n)
{
    int i;
    for (i = 0; i < n; i++)
        scanf_s("%d", p+i);
    for (int j = 0; j < n; j++)
        printf("%d\t", p[j]);
    printf("\n");
}
void work(int *src, int len)
{
    int max, min, maxlen = 0, minlen = 0;
    max = min = src[0];   // 初始化最大、最小值暂时为第一个
    for (int i = 1; i <len; i++)
    {         if (max <src[i]) // If the element is larger than the maximum number, reset the maximum value and its index         {             max = src[i];             maxlen = i;




 

Guess you like

Origin blog.csdn.net/progess_every_day/article/details/104869731