编写程序,从键盘输入两个数,按由小到大的顺序输出(用指针来表现)

c语言编程

第1个回答  2011-06-21
#include<iostream>
using namespace std;
void main(){
int a,b,*p,*q;
cout<<"请输入一个整数"<<endl;
cin>>a;
p=&a;
cout<<"请输入另一个整数"<<endl;
cin>>b;
q=&b;
if(*p>*q) cout<<*q<<" "<<*p;
else cout<<*p<<" "<<*q;
}
第2个回答  2011-06-21
#include <stdio.h>
void sort(int *a,int *b)
{
int t;
if(*a>*b)
{
t=*a;
*a=*b;
*b=t;
}
}
int main()
{
int x,y;
scanf("%d%d",&x,&y);
sort(&x,&y);
printf("%d %d\n",x,y);
return 0;
}本回答被提问者采纳
第3个回答  2019-04-21
#include<stdio.h>
int main(void)
{
int a, b, *p1, *p2, *p;
printf("input a, b:");
scanf("%d,%d", &a, &b);
p1 = &a;
p2 = &b;
/*********Found************/
if (*p1 < *p2)
{
p = p1;
p1 = p2;
p2 = p;
}
printf("a=%d b=%d\n", a, b);
/*********Found************/
printf("max=%d min=%d\n", *p1, *p2);
return 0;
}
相似回答