C语言刷题(17):用指针变量作为函数参数传值,对输入的两个整数按大小顺序输出

#include <stdio.h>
void main(void)
{
    void swap(int *a,int *b);
    int a ,b ,*p,*q;
    p = &a;
    q = &b;
    printf("input a and b:");
    scanf("%d %d",&a,&b);
    if(*p<*q)
    {
        swap(p,q);
    }
    printf("max = %d min = %d",*p,*q);
}
void swap(int *a,int *b)
{
    int t;
    t = *a;
    *a = *b;
    *b = t;
}

结果:
input a and b:5 66
max = 66 min = 5

发布了45 篇原创文章 · 获赞 7 · 访问量 1610

猜你喜欢

转载自blog.csdn.net/qq_38173631/article/details/103994982
今日推荐