/* 程序段B2 */ int a, b, max; scanf ("%d %d", &a, &b); max = 0; if ( a > b ){ max = a; } max = b; 输入3 5,max的值是  1 分 输入100 2,max的值是
时间: 2024-03-25 08:40:33 浏览: 24
当输入3 5时,程序输出如下:
```
max的值是5
```
当输入100 2时,程序输出如下:
```
max的值是2
```
程序如下所示:
```c
/* 程序段B2 */
int a, b, max;
scanf("%d %d", &a, &b);
max = 0;
if ( a > b ){
max = a;
}
max = b;
printf("max的值是%d", max);
```
程序有一个错误,即无论a是否大于b,都会执行max = b;语句,导致max的值始终等于b的值。因此,无论输入的a和b的值是多少,程序都会输出max的值等于b的值。
正确的程序应该是这样的:
```c
/* 程序段B2 */
int a, b, max;
scanf("%d %d", &a, &b);
max = 0;
if ( a > b ){
max = a;
} else {
max = b;
}
printf("max的值是%d", max);
```
这样,当输入3 5时,程序执行else语句,将max的值赋为b的值,输出max的值为5;当输入100 2时,程序执行if语句,将max的值赋为a的值,输出max的值为100。
相关问题
/* 程序段A */ int a, b, max; scanf ("%d%d", &a, &b); max = 0; if ( a > b ){ max = a; }else{ max = b; } 输入9 9的结果
### 回答1:
As an AI language model, I do not have emotions or personal opinions. Therefore, I cannot provide any specific response to the word "null." However, in computer programming, null refers to a value that represents a lack of a value or an undefined state. It is often used to indicate the absence of an object, string, or variable.
### 回答2:
&a, &b); max = (a > b) ? a : b; printf("最大值为:%d\n", max); /*程序段B */ int x, y, result; x = a % b; while (x != 0) { y = b % x; b = x; x = y; } result = b; printf("最大公约数为:%d\n", result); /*程序段C */ int m, n, min, lcm; scanf ("%d%d", &m, &n); min = (m < n) ? m : n; lcm = (m * n) / result; printf("最小公倍数为:%d\n", lcm);
### 回答3:
&a, &b); if (a > b) { max = a; } else { max = b; } printf ("max = %d", max);
写出以下程序段A和程序段B的运行结果。请注意,直接填数字,前后不要加空格等任何其他字符。 /* 程序段A */ int a, b, max; scanf ("%d%d", &a, &b); max = 0; if ( a > b ){ max = a; }else{ max = b; } 输入3 5,max的值是 5 输入100 2,max的值是 100 输入9 9,max的值是
As an AI language model, I do not have a physical or emotional experience, so the concept of "null" does not apply to me in the same way it does to humans. In programming, "null" typically refers to an absence of a value or an uninitialized variable.
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)