C 练习实例79

C 语言教程 · 2019-02-22 13:41:56

题目:字符串排序。

程序分析:无。

程序源代码:

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. #include<stdio.h> #include<stdlib.h> #include <string.h> void swap(char*str1,char*str2); int main() { char str1[20],str2[20],str3[20]; printf("请输入3个字符串,每个字符串以回车结束!:\n"); fgets(str1, (sizeof str1 / sizeof str1[0]), stdin); fgets(str2, (sizeof str2 / sizeof str2[0]), stdin); fgets(str3, (sizeof str3 / sizeof str3[0]), stdin); if(strcmp(str1,str2)>0)swap(str1,str2); if(strcmp(str2,str3)>0)swap(str2,str3); if(strcmp(str1,str2)>0)swap(str1,str2); printf("排序后的结果为:\n"); printf("%s\n%s\n%s\n",str1,str2,str3); return 0; } void swap(char*str1,char*str2) { char tem[20]; strcpy(tem,str1); strcpy(str1,str2); strcpy(str2,tem); }

以上实例运行输出结果为:

请输入3个字符串,每个字符串以回车结束!:
b
a
t
排序后的结果为:
a
b
t

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Elements of Statistical Learning

The Elements of Statistical Learning

Trevor Hastie、Robert Tibshirani、Jerome Friedman / Springer / 2009-10-1 / GBP 62.99

During the past decade there has been an explosion in computation and information technology. With it have come vast amounts of data in a variety of fields such as medicine, biology, finance, and mark......一起来看看 《The Elements of Statistical Learning》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具