栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

字符数组排序

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

字符数组排序

输入五个国家的名称按字母顺序排列输出。 

#define _CRT_SECURE_NO_WARNINGS \Microssoft Visual Studio非搞得跟别人不一样
#include 
#include 
int main()
{
	char country_name[5][20], temp[20];
	int i, j, p;
	printf("input country's name:n");
	for (i = 0; i < 5; i++)
	{
		gets(country_name[i]);
	}
	printf("n");
	for (i = 0; i < 5; i++)
	{
		p = i;
		strcpy(temp, country_name[i]);
		for (j = i + 1; j < 5; j++)
		{
			if (strcmp(country_name[j], temp) < 0)
			{
				p = j;
				strcpy(temp, country_name[j]);
			}
		}
		if (p != i)
		{
			strcpy(temp, country_name[i]);
			strcpy(country_name[i], country_name[p]);
			strcpy(country_name[p], temp);
		}
		puts(country_name[i]);
	}
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/718158.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号