利用指针顺序输出数字

#include<stdio.h>
void temp(int *a, int *b)//交换地址
{
    
    
	int *t;
	t = *a;
	*a = *b;
	*b = t;
}
int main()
{
    
    
	int a, b, c;
	int* p1, * p2, * p3;
	scanf_s("%d", &a);
	p1 = &a;
	scanf_s("%d", &b);
	p2 = &b;
	scanf_s("%d", &c);
	p3 = &c;
	if (*p1 > *p2)
	{
    
    
		temp(p1, p2);
	}
	if (*p1 > *p3)
	{
    
    
		temp(p1, p3);
	}
	if (*p2 > *p3)
	{
    
    
		temp(p2, p3);
	}
	printf("%d %d %d", *p1, *p2, *p3);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_52001969/article/details/111242978