比较两个数,并输出其中较大者
/*
Date: 2019年7月30日
function:比较两个数的最大值(两种不同的表示方式),并输出
学习scanf 输入语句
学习if else 条件语句
*/
#include<stdio.h> //printf and scanf 的函数声明在stdio.h中,但函数定义在库中
int main(void)
{
double a, b; //double 浮点型数据类型,可以看做小数
printf("please input two numbers: ");
scanf("%lf,%lf", &a, &b); // & 取地址符; %lf 是在对一个浮点型数据进行格式输入输出所用到的格式说明符
printf("a = %lf, b = %lf\n", a, b);
/* method one
if(a >= b)
printf("a is max, a = %lf\n", a);
else
printf("b is max, b = %lf\n", b);
return 0;
*/
//method two
if(a < b) //表达式是数值和运算符的组合
a = b;
printf("max = % lf\n", a);
return 0;
}
/*
please input two numbers: 13.14,52.0 //输入格式与scanf规定的格式要一致
a = 13.140000, b = 52.000000
max = 52.000000
Press any key to continue
*/