c语言字符串大小比较输入两个数a和b,比较两个数的大小,输出比较的结果
时间: 2023-12-15 14:32:57 浏览: 231
以下是比较两个字符串大小的C语言代码:
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100], str2[100];
int result;
printf("请输入第一个字符串:");
scanf("%s", str1);
printf("请输入第二个字符串:");
scanf("%s", str2);
result = strcmp(str1, str2);
if (result < 0)
{
printf("%s 小于 %s\n", str1, str2);
}
else if (result == 0)
{
printf("%s 等于 %s\n", str1, str2);
}
else
{
printf("%s 大于 %s\n", str1, str2);
}
return 0;
}
```
该代码中,我们使用了C语言内置的函数strcmp来比较两个字符串的大小。首先,我们定义了两个字符数组str1和str2,分别用于存储用户输入的两个字符串。然后,我们使用scanf函数从用户处获取输入,并将其存储到相应的字符数组中。接着,我们使用strcmp函数比较两个字符串的大小,并将结果存储到result变量中。最后,我们根据result的值输出比较结果。
阅读全文
相关推荐
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)