C语言基础 -43 函数_嵌套

book@100ask:~/C_coding/CH02$ cat test.c
#include <stdio.h>
#include <stdlib.h>

int dist(int a,int b,int c)
{
    return max(a,b,c) - min(a,b,c);
}

int max(int a,int b,int c)
{
    int tmp;
    tmp = a > b ? a : b;
    return tmp > c ? tmp : c;
}

int min(int a,int b,int c)
{
    int tmp;
    tmp = a < b ? a : b;
    return tmp < c ? tmp : c;
}

int main()
{
	int a = 3,b = 5,c = 10;
    int res;

    res = dist(a,b,c);
    printf("res = %d\n",res);
	return 0;
}

函数再去调用函数,就是嵌套

函数的原子性越好,越容易移植。

猜你喜欢

转载自blog.csdn.net/f2157120/article/details/106938521
43