文章目录
  1. 1. 数组中找数

龙珠-插画-Tao Pai Pa
功能函数备忘,速查。

C


数组中找数

  1. 找出数组中最大元素和最小元素
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include<stdio.h>
    #define N 10
    void max_min(int a[], int n, int *max, int *min);

    int main(void)
    {

    int b[N], i, big, small;

    printf("Enter %d numbers: ", N);
    for (i = 0; i < N; i++)
    scanf("%d", &b[i]);

    max_min(b, N, &big, &small);

    printf("Largest: %d\n", big);
    printf("Smallest: %d\n", small);
    return 0;
    }

    void max_min(int a[], int n, int *max, int *min)
    {

    int i;

    *max = *min = a[0];
    for (i = 1; i < n; i++) {
    if (a[i] > *max)
    *max = a[i];
    else if (a[i] < *min)
    *min = a[i];
    }
    }
文章目录
  1. 1. 数组中找数