標題:
兩數對調
[打印本頁]
作者:
tonyh
時間:
2016-12-17 14:00
標題:
兩數對調
本帖最後由 tonyh 於 2019-10-31 21:17 編輯
[attach]3168[/attach]
#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;
}
複製代碼
作者:
黃宥鈞
時間:
2016-12-17 14:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,z;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
z=x;
x=y;
y=z;
cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳承勳
時間:
2016-12-17 14:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y, tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
tmp=x;
x=y;
y=tmp;
cout<<"對調前: ";
cout<<"x="<<x<<"y="<<y<<endl<<endl;
cout<<"對調後: ";
cout<<"x="<<y<<"y="<<x<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳晉榕
時間:
2016-12-17 14:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y,;
cout<<"請輸入兩個整數: ";
cin>>x>>y;
cout<<"[對調前]";
cout<<"x="<<x<<"y="<<y<<endl<<endl;
cout<<"[對調後]";
cout<<"x="<<y<<"y="<<x<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2016-12-17 14:51
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x, y, tmp;
cout<<"Please enter a number: ";
cin>>x;
cout<<"Please enter another number: ";
cin>>y;
cout<<"Before the change"<<endl;
cout<<"x= "<<x<<" y= "<<y<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"After the change"<<endl;
cout<<"x= "<<x<<" y= "<<y<<endl;
goto re;
return 0;
}
複製代碼
作者:
朱聿謙
時間:
2016-12-17 14:51
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
tmp=x;
x=y;
y=tmp;
cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2016-12-17 14:52
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,z;
cout<<"請輸入兩個數:";
cin>>x>>y;
cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
z=x;
x=y;
y=z;
cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
system("pause");
return 0;
system("pause");
return 0;
}
複製代碼
作者:
康湍榆
時間:
2016-12-17 14:57
#include<iostream>
using namespace std;
int main()
{
int a, b,tmp;
cout<<"請輸入a和b: ";
cin>>a>>b;
cout<<"對調前:"<<"a="<<a<<" b="<<b<<endl;
tmp=a;
a=b;
b=tmp;
cout<<"對調後:"<<"a="<<a<<" b="<<b<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2016-12-17 14:59
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x, y, tm;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<"對調前: ";
cout<<"x="<<x<<"y="<<y<<endl;
tm=x;
x=y;
y=tm;
cout<<"對調後: ";
cout<<"x="<<x<<"y="<<y<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2016-12-17 15:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x, y, tmp;
cout<<"請輸入第一個數: ";
cin>>x;
cout<<"請輸入第二個數: ";
cin>>y;
tmp=x;
x=y;
y=tmp;
cout<<"正在交換數值!請稍候!已完成100%..."<<endl;
cout<<"交換完畢!"<<endl;
cout<<"x="<<x<<"y="<<y<<endl<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
許紘誌
時間:
2016-12-19 13:57
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>a>>b;
cout<<"對調前: ";
cout<<"a="<<a<<" b="<<b<<endl<<endl;
tmp=a;
a=b;
b=tmp;
cout<<"對調後: ";
cout<<"a="<<a<<" b="<<b<<endl<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2