(C语言)找出最大的字符串

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

#include <stdio.h>
#include<string.h>
int main()
{
	char str[10], temp[10];
	int i;
	printf("输入五个字符串\n");
	gets(temp);
	for (i = 0; i < 4; i++) {
		gets(str);             //输入剩下四个字符串
		if (strcmp(str,temp) > 0) {     //若后输入的字符串比前面的大
			strcpy(temp, str);			//将较大的字符串存入temp[]
		}
	}
	printf("最大的字符串是%s\n", temp);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Dax1_/article/details/105335102