C 练习实例66

C 语言教程 · 2019-02-22 10:26:30

题目:输入3个数a,b,c,按大小顺序输出。

程序分析:利用指针方法。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // # include<stdio.h> void swap(int *, int *); int main(void) { int a, b, c; int *p1, *p2, *p3; printf("输入 a, b ,c:\n"); scanf("%d %d %d", &a, &b, &c); p1 = &a; p2 = &b; p3 = &c; if(a>b) swap(p1, p2); if(a>c) swap(p1, p3); if(b>c) swap(p2, p3); printf("%d %d %d\n", a, b, c); } void swap(int *s1, int *s2) { int t; t = *s1; *s1 = *s2; *s2 = t; }

以上程序执行输出结果为:

输入 a, b ,c:
1 3 2
1 2 3

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

查看所有标签

Principles of Object-Oriented JavaScript

Principles of Object-Oriented JavaScript

Nicholas C. Zakas / No Starch Press / 2014-2 / USD 24.95

If you've used a more traditional object-oriented language, such as C++ or Java, JavaScript probably doesn't seem object-oriented at all. It has no concept of classes, and you don't even need to defin......一起来看看 《Principles of Object-Oriented JavaScript》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

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

在线 XML 格式化压缩工具