公告

Gentoo交流群:87709706 欢迎您的加入

#1 2022-08-29 20:39:27

batsom
管理团队
注册时间: 2022-08-03
帖子: 594
个人网站

C 练习实例66

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

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

# 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;
}

离线

页脚

Powered by FluxBB

本站由XREA提供空间支持