C 练习实例66

C语言教程评论

C 练习实例66

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

程序分析:利用指针方法。文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili66.html

实例

# 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;
}
文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili66.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili66.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月6日20:52:39
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili66.html

发表评论