作业帮 > 综合 > 作业

b中的最大值,用C语言如何表达,用简单的方式

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 02:14:36
b中的最大值,用C语言如何表达,用简单的方式
请问这儿哪儿错了
#include(stdio.h)
main()
{
int a,b,max
printf("please input a number:\n);
scanf("%d,%d\n",&a,&b);
max=(a,b);
if (a>b),max=a;
if (b>a),max=b;
printf("max=%d".max);
}
定义个宏
#define max(x,y) (a > b a :b)
然后就可以用max来得到两个数的最大值了
再问: 请问这里哪儿错了 #include(stdio.h) main( ) { int a,b,max printf("please input a number:\n); scanf("%d,%d\n",&a,&b); max=(a,b); if (a>b),max=a; if (b>a),max=b; printf("max=%d".max); }
再答: #include /* 用尖括号 */ main( ) { int a,b,max; //少了分号结尾 printf("please input a number:\n); scanf("%d,%d\n",&a,&b); if (a>=b) max=a; /* 不能有逗号 */ else max=b; printf("max=%d", max); /*max前应该是逗号*/ }
再问: 按你说的我改成这样: #include /* 用尖括号 */ main( ) { int a,b,max; //少了分号结尾 printf("please input a number:\n"); scanf("%d,%d\n",&a,&b); if (a>=b) max=a; /* 不能有逗号 */ else max=b; printf("max=%d", max); /*max前应该是逗号*/ } 显示无错误 可我在dos里输入7和9按回车后,啥数字也没显示出来
再答: printf("max=%d\n", max); 加个回车就出来了
再问: 加过了,没有用,出来的不是最大的数,中间坑定有错误了
再答: scanf("%d,%d\n",&a,&b); 输入两个数之间要加逗号,如: 1,2 或者去掉逗号,把程序改为: scanf("%d %d\n",&a,&b);
再问: 懂了,懂了 发现错误了 谢谢