#include<stdio.h>
/*
练习指针:
通过指针变量求三个整数中的最大数和最小数。
*/
void main()
{
int a, b, c;
int *pmax, *pmin;
//pmax变量中存放最大数的地址,pmin变量中存放最小数的地址。
printf("please input three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if(a > b)
{
pmax = &a;
pmin = &b;
}
else
{
pmax = &b;
pmin = &a;
}
if(c > *pmax)
{
pmax = &c;
}
else if(c < *pmin)
{
pmin = &c;
}
printf("max = %d\nmin = %d\n",*pmax, *pmin);
}
指针练习一
最新推荐文章于 2024-01-11 15:09:57 发布