(1)找最长字符串:输入5个字符串,输出其中最长的字符串。输人字符串调用函数为scanf("%s”,sx);。 试编写相应程序。
输入输出示例
li wang zhang jin xian
zhang
#include<stdio.h>
#include<string.h>
int main()
{
int i;
char max[10],sx[10];
scanf("%s",sx);
strcpy(max,sx);
for(i=0;i<4;i++){
scanf("%s",sx);
if(strlen(sx)>strlen(max))
strcpy(max,sx);
}
printf("%s",max);
return 0;
}
该程序使用C语言编写,旨在找出输入的5个字符串中长度最长的一个。通过scanf函数读取每个字符串,然后利用strlen函数比较字符串长度,将最长的字符串存储在变量max中。最后,程序打印出最长的字符串。
3032

被折叠的 条评论
为什么被折叠?



