返回列表 發帖

五則運算(二)

使用 cin 讓使用者能自行指定 x 與 y 的值.
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y;
  7.    
  8.     cout<<"請輸入一整數x:";
  9.     cin>>x;
  10.     cout<<"請輸入一整數y:";
  11.     cin>>y;
  12.    
  13.     cout<<x<<"+"<<y<<"="<<x+y<<endl;
  14.     cout<<x<<"-"<<y<<"="<<x-y<<endl;
  15.     cout<<x<<"*"<<y<<"="<<x*y<<endl;
  16.     cout<<x<<"/"<<y<<"="<<x/y<<endl;
  17.     cout<<x<<"%"<<y<<"="<<x%y<<endl;
  18.    
  19.     system("pause");
  20.     return 0;
  21.    
  22.    
  23.     }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x=10,y=3;
  7.     cout<<"當x的值:";
  8.     cin>>x;
  9.     cout<<"當y的值:";
  10.     cin>>y;
  11.     cout<<"x+y="<<x+y<<endl;
  12.     cout<<"x-y="<<x-y<<endl;
  13.     cout<<"x*y="<<x*y<<endl;
  14.     cout<<"x/y="<<x/y<<endl;
  15.     cout<<"x%y="<<x%y<<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<<"請輸入x的值:";
  8.     cin>>x;
  9.     cout<<"請輸入y的值:";
  10.     cin>>y;
  11.     cout<<x<<"+"<<y<<"="<<x+y<<endl;
  12.     cout<<x<<"-"<<y<<"="<<x-y<<endl;
  13.     cout<<x<<"*"<<y<<"="<<x*y<<endl;
  14.     cout<<x<<"/"<<y<<"="<<x/y<<endl;
  15.     cout<<x<<"%"<<y<<"="<<x%y<<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<<"請輸入x的值:";
  8.       cin>>x;
  9.     cout<<"請輸入y的值:";
  10.       cin>>y;
  11.        cout<<x<<"*"<<y<<x+y<<endl;
  12.     cout<<"x-y="<<x-y<<endl;
  13.     cout<<"x*y="<<x*y<<endl;
  14.     cout<<"x/y="<<x/y<<endl;
  15.     cout<<"x%y="<<x%y<<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=10,Y=3;
  7.     cout<<"請輸入X值:";
  8.     cin>>X;
  9.     cout<<"請輸入Y值:";
  10.     cin>>Y;
  11.     cout<<"X+Y="<<X+Y<<endl;
  12.     cout<<"x-Y="<<X-Y<<endl;
  13.     cout<<"X*Y="<<X*Y<<endl;
  14.     cout<<"X/Y="<<X/Y<<endl;
  15.     cout<<"X%Y="<<X%Y<<endl;
  16.     system("pause");
  17.     return 0;
  18.                            
  19. }
複製代碼

TOP

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

TOP

本帖最後由 章幼莛 於 2018-10-13 14:29 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     float x,y;
  7.     cout<<"請輸入整數x:";
  8.     cin>>x;
  9.     cout<<"請輸入整數y:";
  10.     cin>>y;
  11.     cout<<"當x為:"<<x<<endl;
  12.     cout<<"當y為:"<<y<<endl;
  13.     cout<<x<<"+"<<y<<"="<<x+y<<endl;
  14.     cout<<x<<"-"<<y<<"="<<x-y<<endl;
  15.     cout<<x<<"*"<<y<<"="<<x*y<<endl;
  16.     cout<<x<<"/"<<y<<"="<<x/y<<endl;
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

本帖最後由 曲書辰 於 2018-10-13 14:01 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int X,Y;
  7.     cout<<"請輸入X的值:";
  8.     cin>>X;
  9.     cout<<"請輸入Y的值:";
  10.     cin>>Y ;
  11.     cout<<X<<" + "<<Y<<" = "<<X+Y<<endl;
  12.     cout<<X<<" - "<<Y<<" = "<<X+Y<<endl;
  13.     cout<<X<<" * "<<Y<<" = "<<X+Y<<endl;
  14.     cout<<X<<" / "<<Y<<" = "<<X+Y<<endl;
  15.     cout<<X<<" % "<<Y<<" = "<<X+Y<<endl;
  16.     system("pause");
  17.     return 0;   
  18.    
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int x,y;
  8.     cout<<"請輸入x的質:";
  9.     cin>>x;
  10.     cout<<"請輸入y的質:";
  11.      cin>>y;
  12.     cout<<"x+y="<<x+y<<endl;
  13.     cout<<"x-y="<<x-y<<endl;
  14.     cout<<"x*y="<<x*y<<endl;
  15.     cout<<"x/y="<<x/y<<endl;
  16.     cout<<"x%y="<<x%y<<endl;
  17.      system("pause");
  18.      return 0;
  19. }
複製代碼

TOP

本帖最後由 趙一鳴 於 2018-10-13 14:30 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y;
  7.     cout<<"請輸入整數x:";
  8.     cin>>x;
  9.     cout<<"請輸入整數y:";
  10.     cin>>y;
  11.     cout<<x<<"+"<<y<<"="<<x+y<<endl;
  12.     cout<<x<<"-"<<y<<"="<<x-y<<endl;
  13.     cout<<x<<"*"<<y<<"="<<x*y<<endl;
  14.     cout<<x<<"/"<<y<<"="<<x/y<<endl;
  15.     cout<<x<<"%"<<y<<"="<<x%y<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

TOP

返回列表