当前位置: 代码迷 >> 综合 >> 考研专业课学习日记2—C语言(从0开始)软件工程专业考研
  详细解决方案

考研专业课学习日记2—C语言(从0开始)软件工程专业考研

热度:52   发布时间:2023-10-30 13:48:37.0

比较两个数,并输出其中较大者

/*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 oneif(a >= b)printf("a is max, a = %lf\n", a);elseprintf("b is max, b = %lf\n", b);return 0;
*///method twoif(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.000000max =  52.000000Press any key to continue
*/