分支和三目运算符两种方法求最大数:
//使用 c 语言编写程序,求两个整数的较大值。
#include<stdlib.h>
typedef int ElemType;
ElemType Judgement_tow_num_size();
int main()
{
ElemType a, b;
scanf("%d%d", &a, &b);
printf("%d\n",Judgement_tow_num_size(a, b));
printf("%d\n", Judgement_tow_num_size1(a, b));
return 0;
}
ElemType Judgement_tow_num_size(ElemType x, ElemType y)
{
if (x > y)
{
return x;
}
else
{
return y;
}
}
ElemType Judgement_tow_num_size1(ElemType x, ElemType y)
{
return x > y ? x : y;
}
测试结果: