输入5个字符串,输出其中最大的字符串。

2025-03-12 13:51:45
推荐回答(1个)
回答1:

strcpy(max,str)完成字符串拷贝,strcmp完成字符串比较,只要保留一个for循环,用一个strcmp就解决问题。
strcmp(str1,str2):
str1>str2时strcmp()>0,
str1=str2时strcmp()=0,
str1
#include
#include
#include
int main(void)
{
char str[80], max[80];
int i;
scanf("%s", &max);
for(k=1;k<=4;k++)
{
scanf("%s", &str);
if(strcmp(max,str)<0)
strcpy(max,str);
}
printf("Max is: %s\n", max);
}
简单的很的程序!
希望能解决您的问题。