標題:
兩數對調
[打印本頁]
作者:
方浩葦
時間:
2024-7-6 12:02
標題:
兩數對調
#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;
}
複製代碼
作者:
高湘庭
時間:
2024-7-6 14:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int x,y,tmp;
re:
system("cls");
cout<<"請依序輸入兩正整數";
cin>>x>>y;
cout<<"x="<<x<<"y="<<y<<endl;
tmp=x;//x值丟給tmp
x=y;//y值丟給x
y=tmp;//同理
cout<<endl;
cout<<"對調後:"<<endl;
cout<<"x="<<x<<"y="<<y<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李唯銘
時間:
2024-7-6 14:42
本帖最後由 李唯銘 於 2024-7-6 14:45 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x,y,z;
cout<<"依序輸入兩個數"<<endl;
cin>>x>>y;
cout<<"對調前:x="<<x<<" y="<<y<<endl;
z=x;
x=y;
y=z;
cout<<"對調後:x="<<x<<" y="<<y<<endl;
system ("pause");
goto re;
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-6 14:44
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a,b,c;
cout<<"請依序輸入兩個數: ";
cin>>a>>b;
cout<<"對調前:";
cout<<"a="<<a<<",b="<<b<<endl;
c=a;
a=b;
b=c;
cout<<"對調後: ";
cout<<"a="<<a<<",b="<<b<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林少謙
時間:
2024-7-6 14:55
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x,y,a;
cout<<"請輸入兩個正整數:";
cin>>x>>y;
cout<<"對調前x="<<x<<" y="<<y<<endl;
a=x;
x=y;
y=a;
cout<<"對調後x="<<x<<" y="<<y<<endl;
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-6 15:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a,b,tmp;
cout<<"請依序輸入兩個正整數:"<<endl;
cin>>a>>b;
cout<<endl;
cout<<"對調前: "<<"x="<<a<<",y="<<b<<endl;
tmp=a;
a=b;
b=tmp;
cout<<"對調後: "<<"x="<<a<<",y="<<b<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-6 15:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y, tmp;
cout<<"請依序輸入兩個正整數: ";
cin>>x>>y;
cout<<endl;
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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2