返回列表 發帖

兩數對調

本帖最後由 tonyh 於 2019-10-31 21:17 編輯


  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,tmp;
  7.     cout<<"請依序輸入兩個正整數: ";
  8.     cin>>x>>y;
  9.     cout<<"對調前: ";
  10.     cout<<"x="<<x<<" y="<<y<<endl<<endl;
  11.    
  12.     tmp=x;
  13.     x=y;
  14.     y=tmp;
  15.    
  16.     cout<<"對調後: ";
  17.     cout<<"x="<<x<<" y="<<y<<endl<<endl;
  18.    
  19.     system("pause");
  20.     return 0;   
  21. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x,y,z;
  7.     cout<<"請依序輸入兩個正整數: ";
  8.     cin>>x>>y;
  9.     cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
  10.     z=x;
  11.     x=y;
  12.     y=z;
  13.     cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x, y, tmp;
  7.     cout<<"請依序輸入兩個正整數: ";
  8.     cin>>x>>y;
  9.     tmp=x;
  10.     x=y;
  11.     y=tmp;
  12.     cout<<"對調前: ";
  13.     cout<<"x="<<x<<"y="<<y<<endl<<endl;
  14.     cout<<"對調後: ";
  15.     cout<<"x="<<y<<"y="<<x<<endl<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x, y,;
  7.     cout<<"請輸入兩個整數: ";     
  8.     cin>>x>>y;
  9.     cout<<"[對調前]";
  10.     cout<<"x="<<x<<"y="<<y<<endl<<endl;
  11.    cout<<"[對調後]";
  12.    cout<<"x="<<y<<"y="<<x<<endl<<endl;
  13.     system("pause");
  14.     return 0;   
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     re:
  7.     int x, y, tmp;
  8.     cout<<"Please enter a number: ";
  9.     cin>>x;
  10.     cout<<"Please enter another number: ";
  11.     cin>>y;
  12.     cout<<"Before the change"<<endl;
  13.     cout<<"x= "<<x<<" y= "<<y<<endl;
  14.     tmp=x;
  15.     x=y;
  16.     y=tmp;
  17.     cout<<"After the change"<<endl;
  18.     cout<<"x= "<<x<<" y= "<<y<<endl;
  19.     goto re;
  20.     return 0;   
  21. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x,y,tmp;
  7.     cout<<"請依序輸入兩個正整數: ";
  8.     cin>>x>>y;
  9.     cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
  10.     tmp=x;
  11.     x=y;
  12.     y=tmp;
  13.     cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,z;
  7.     cout<<"請輸入兩個數:";
  8.     cin>>x>>y;
  9.     cout<<"對調前:"<<endl<<" x="<<x<<" y="<<y<<endl;
  10.     z=x;
  11.     x=y;
  12.     y=z;
  13.     cout<<"對調後:"<<endl<<" x="<<x<<" y="<<y<<endl;
  14.     system("pause");
  15.     return 0;
  16.        system("pause");                  
  17.        return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a, b,tmp;
  6.     cout<<"請輸入a和b: ";
  7.     cin>>a>>b;
  8.     cout<<"對調前:"<<"a="<<a<<"        b="<<b<<endl;
  9.     tmp=a;
  10.     a=b;
  11.     b=tmp;
  12.     cout<<"對調後:"<<"a="<<a<<"        b="<<b<<endl;
  13.     system("pause");
  14.     return 0;   
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     re:
  7.     int x, y, tm;
  8.     cout<<"請依序輸入兩個正整數: ";
  9.     cin>>x>>y;
  10.     cout<<"對調前: ";
  11.     cout<<"x="<<x<<"y="<<y<<endl;
  12.    
  13.     tm=x;
  14.     x=y;
  15.     y=tm;
  16.    
  17.     cout<<"對調後: ";
  18.     cout<<"x="<<x<<"y="<<y<<endl;
  19.    
  20.     goto re;
  21.     system("pause");
  22.     return 0;   
  23. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int x, y, tmp;
  8.     cout<<"請輸入第一個數: ";
  9.     cin>>x;
  10.     cout<<"請輸入第二個數: ";
  11.     cin>>y;
  12.     tmp=x;
  13.     x=y;
  14.     y=tmp;
  15.     cout<<"正在交換數值!請稍候!已完成100%..."<<endl;
  16.     cout<<"交換完畢!"<<endl;
  17.     cout<<"x="<<x<<"y="<<y<<endl<<endl;
  18.     goto re;
  19.     system("pause");
  20.     return 0;
  21. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b,tmp;
  7.     cout<<"請依序輸入兩個正整數: ";
  8.     cin>>a>>b;
  9.     cout<<"對調前: ";
  10.     cout<<"a="<<a<<" b="<<b<<endl<<endl;
  11.    
  12.     tmp=a;
  13.     a=b;
  14.     b=tmp;
  15.    
  16.     cout<<"對調後: ";
  17.     cout<<"a="<<a<<" b="<<b<<endl<<endl;
  18.    
  19.     system("pause");
  20.     return 0;   
  21. }
複製代碼

TOP

返回列表