C 练习实例5

C 语言教程 · 2019-02-21 13:14:37

题目:输入三个整数x,y,z,请把这三个数由小到大输出。

程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> int main() { int x,y,z,t; printf("\n请输入三个数字:\n"); scanf("%d%d%d",&x,&y,&z); if (x>y) { /*交换x,y的值*/ t=x;x=y;y=t; } if(x>z) { /*交换x,z的值*/ t=z;z=x;x=t; } if(y>z) { /*交换z,y的值*/ t=y;y=z;z=t; } printf("从小到大排序: %d %d %d\n",x,y,z); }

以上实例输出结果为:

请输入三个数字:
1
3
2
从小到大排序: 1 2 3

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

查看所有标签

Software Engineering for Internet Applications

Software Engineering for Internet Applications

Eve Andersson、Philip Greenspun、Andrew Grumet / The MIT Press / 2006-03-06 / USD 35.00

After completing this self-contained course on server-based Internet applications software, students who start with only the knowledge of how to write and debug a computer program will have learned ho......一起来看看 《Software Engineering for Internet Applications》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

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

HSV CMYK互换工具