【C语言经典100例题-66】(用指针解决)输入3个数a,b,c,按大小顺序输出。

代码: 

#include
#define _CRT_SECURE_NO_WARNINGS 1//VS编译器使用scanf函数时会报错,所以添加宏定义
swap(p1, p2)
int* p1, * p2;
{
	int p;
	p = *p1;*p1 = *p2;*p2 = p;
}
int main()
{
	int n1, n2, n3;
	int* pointer1, * pointer2, * pointer3;
	printf("please input 3 number:n1,n2,n3:");
	scanf("%d,%d,%d", &n1, &n2, &n3);
	pointer1 = &n1;
	pointer2 = &n2;
	pointer3 = &n3;
	if (n1 > n2) swap(pointer1, pointer2);
	if (n1 > n3) swap(pointer1, pointer3);
	if (n2 > n3) swap(pointer2, pointer3);
	printf("the sorted numbers are:%d,%d,%d\n", n1, n2, n3);
}

运行结果:【C语言经典100例题-66】(用指针解决)输入3个数a,b,c,按大小顺序输出。_第1张图片

 

你可能感兴趣的:(C语言经典100例题,c语言)