1041: C语言程序设计教程(第三版)课后习题9.8

题目描述

分别用函数和带参的宏,从三个数中找出最大的数。

输入

3个实数

输出

最大的数,输出两遍,先用函数,再用宏。 保留3位小数。

样例输入

1 2 3

样例输出

3.000
3.000

 

 1 #include <stdio.h>
 2 #define MAX(a, b, c) temp = a > b ? a : b; temp = temp > c ? temp : c; printf("%.3f
", temp);
 3 
 4 float max(float a, float b, float c)
 5 {
 6     float max = a > b ? a : b;
 7     return max > c ? max : c;
 8 }
 9 
10 int main(int argc, char const *argv[])
11 {
12     float a, b, c, temp;
13     scanf("%f%f%f", &a, &b, &c);
14     printf("%.3f
", max(a, b, c));
15     MAX(a, b, c);
16     return 0;
17 }
原文地址:https://www.cnblogs.com/hello-lijj/p/7872828.html