標題:
兩數對調
[打印本頁]
作者:
tonyh
時間:
2019-11-8 19:36
標題:
兩數對調
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃辰昊
時間:
2019-11-8 20:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃宥華
時間:
2019-11-8 20:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,pig;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
pig=x;
x=y;
y=pig;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林政瑜
時間:
2019-11-8 20:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李宇澤
時間:
2019-11-8 20:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請依序輸入兩個正整數: ";
cin>>a>>b;
cout<<"對調前: ";
cout<<"x="<<a<<" y="<<b<<endl<<endl;
c=a;
a=b;
b=c;
cout<<"對調後: ";
cout<<"x="<<a<<" y="<<b<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡忻霓
時間:
2019-11-8 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
施褕均
時間:
2019-11-8 20:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
int x, y, tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<"y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<"y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳宥穎
時間:
2019-11-8 20:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,c;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;//x=1 y=2
c=x;//c=1
x=y;//x=2
y=c;//y=1
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
余有晉
時間:
2019-11-8 20:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: ";
cout<<"x="<<x<<" y="<<y<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
董宸佑
時間:
2019-11-8 20:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y, tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: x="<<x<<" y="<<y<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後: x="<<x<<" y="<<y<<endl;
system("pause");
return 0;
}
複製代碼
作者:
孫嘉駿
時間:
2019-11-8 20:14
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int g, h ,f;
cout<<"請依序輸入兩個正整數: ";
cin>>g>>h;
cout<<"對調前: g="<<g<<" h="<<h<<endl;
f=g;
g=h;
h=f;
cout<<"對調後: g="<<g<<" h="<<h<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2