输入两个学生的年龄 要求输出其中较大的年龄用c语言
时间: 2023-04-10 08:01:34 浏览: 294
我可以回答这个问题。以下是用 C 语言实现的代码:
```
#include <stdio.h>
int main() {
int age1, age2;
printf("请输入两个学生的年龄:\n");
scanf("%d %d", &age1, &age2);
if (age1 > age2) {
printf("较大的年龄是:%d\n", age1);
} else {
printf("较大的年龄是:%d\n", age2);
}
return 0;
}
```
希望能帮到你!
相关问题
输入两个字符串输出较大者C语言
以下是输入两个字符串输出较大者的C语言代码:
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100], str2[100];
printf("请输入第一个字符串:");
scanf("%s", str1);
printf("请输入第二个字符串:");
scanf("%s", str2);
if (strlen(str1) > strlen(str2))
{
printf("较大的字符串是:%s\n", str1);
}
else if (strlen(str1) < strlen(str2))
{
printf("较大的字符串是:%s\n", str2);
}
else
{
printf("两个字符串长度相等。\n");
}
return 0;
}
```
用C语言输入两个整数,输出其中的较小值
ChatGPT: 以下是用 C 语言输入两个整数,输出其中的较小值的代码:
```c
#include <stdio.h>
int main() {
int a, b;
printf("请输入两个整数:\n");
scanf("%d %d", &a, &b);
if (a < b) {
printf("较小的数是:%d\n", a);
} else {
printf("较小的数是:%d\n", b);
}
return 0;
}
```
希望这个代码能够帮到你!
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.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)