[YTU]_2738 指针练习--变量交换
Description
注:本題只需要提交填寫部分的代碼
用指針變量對(duì)兩個(gè)整數(shù)按從小到大排序。
/*C++*/
#include <iostream>
using namespace std;
int main()
{
??? int *p1,*p2,*p;
??? int a,b;
??? cin>>a>>b;
??? p1=&a;
??? p2=&b;
??? if(a>b)
??? {
??? /*******************************
???? 請(qǐng)?jiān)谠摬糠盅a(bǔ)充缺少的代碼
??? ********************************/
??? }
??? cout<<"min:"<<*p1<<endl;
??? cout<<"max:"<<*p2<<endl;
??? return 0;
}
/*C*/
#include<stdio.h>
int main()
{
??? int *p1,*p2,*p;
??? int a,b;
??? scanf("%d%d",&a,&b);
??? p1=&a;
??? p2=&b;
??? if(a>b)
??? {
??? /*******************************
???? 請(qǐng)?jiān)谠摬糠盅a(bǔ)充缺少的代碼
??? ********************************/
??? }
??? printf("min:%d\n",*p1);
??? printf("max:%d\n",*p2);
??? return 0;
}
Input
兩個(gè)整數(shù)
Output
按從小到大輸出兩個(gè)整數(shù)
Sample Input
2 1Sample Output
min:1 max:2 #include <iostream> using namespace std; int main() {int *p1,*p2,*p;int a,b;cin>>a>>b;p1=&a;p2=&b;if(a>b){p=p1;p1=p2;p2=p;}cout<<"min:"<<*p1<<endl;cout<<"max:"<<*p2<<endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的[YTU]_2738 指针练习--变量交换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU ]_2736指针练习--输出最
- 下一篇: [YTU]_2570 指针练习——变量交