三个整数比较大小

  本程序最大的亮点就是不加if 判断:

#include<stdio.h>
#include<stdlib.h>

/*
**如果a比b大,返回真值。
*/
bool
judgeMax(int a, int b)
{
	return a > b;
}

/*
**参数a和参数b进行比较,返回较大的。
*/
int
myMax(int a, int b)
{
	bool flag = judgeMax(a, b);
	return flag * a + (1 - flag)*b;
}

int main()
{
	int x = 100;
	int y = 200;
	int max = myMax(x, y);
	printf("%d\n", max);
}

猜你喜欢

转载自blog.csdn.net/qq_41822235/article/details/80295869