返回列表 發帖

五則運算



1. 在程式內宣告兩個整數變數x與y,並自訂兩個數字存放於x與y。
2. 輸出 x 與 y 以下五種結果: 加法、減法、乘法、除法、取餘數
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int x =21;
  7.     int y =5;
  8.    
  9.     cout << "當 x = " << x << ", y = " << y << " 時 "<<endl;
  10.     cout << " x + y = "<< x+y << endl;
  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.    
  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 = 29;
  7.     int y = 2;
  8.     cout << "當 x = " << x << ", y = " << y <<"時:" <<endl;
  9.     cout << "x + y = " << x+y << endl;
  10.     cout << "x - y = " << x-y << endl;
  11.     cout << "x * y = " << x*y << endl;
  12.     cout << "x / y = " << x/y << endl;
  13.     cout << "x % y = " << x%y << endl;
  14.    
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.    int x=21,y=5;
  7.    cout<<"當 x = "<< x <<", y=" << y <<" 時:"<<endl;
  8.     cout <<"x + y = " <<x+y <<endl<< "x - y= "<<x-y <<endl
  9.          <<"x * y = " <<x*y <<endl <<" x / y= " <<x/y <<endl
  10.          <<"x % y = "<<x%y<<endl;
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6.     int x = 21;
  7.     int y = 5;
  8.     cout <<"當 x = "<< x << " ,y = "<<y<<"時"<<endl;
  9.     cout <<" x + y = " << x+y <<endl;
  10.     cout <<" x - y = " << x-y <<endl;
  11.     cout <<" x * y = " << x*y <<endl;
  12.     cout <<" x / y = " << x/y <<endl;
  13.     cout <<" x % y = " << x%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.    
  7.     int x = 21;
  8.     int y = 5;
  9.     cout<<"當 x ="<<x<<". y ="<<y<<"時"<<endl;
  10.     cout<<"x + y ="<<x+y<<endl;
  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.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x = 21;
  7.     int y = 5;
  8.     cout << "當 x =" << x << ", y = " << y << "時" << endl;
  9.     cout << "x + y =" << x+y << endl;
  10.     cout << "x - y =" << x-y << endl;
  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的加減乘除和餘數的運算~" << endl;   
  15.     system("pause");
  16.     return 0;   
  17. }  
複製代碼

TOP

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

TOP

本帖最後由 黃詠軒 於 2014-1-22 12:01 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int x = 21,y = 5;
  7.     cout <<"當 x = "<< x << ",y =" << y << "時:" << endl
  8.          <<"x+y=" <<x+y <<endl <<"x-y=" <<x-y <<endl
  9.          <<"x*y=" <<x*y <<endl <<"x/y=" <<x/y <<endl
  10.          <<"x%y=" <<x%y <<endl;
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>

  3. using namespace std;
  4. int main()
  5. {

  6. int x=21;
  7. int y=5;
  8. cout<<"當x="<< x<<" 當y="<<y<<"時:" <<endl;
  9. cout<< "x + y ="<<x+y<<endl;
  10. cout<< "x - y ="<<x-y<<endl;  
  11. cout<< "x * y ="<<x*y<<endl;
  12. cout<< "x / y ="<<x/y<<endl;
  13. cout<< "x % y ="<<x%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=30678;
  7.     int y=87603;
  8.    
  9.     cout<<"當 X = "<<x<<", y = "<<y<<"時:"<<endl;
  10.     cout<<"x + y ="<<x+y<<endl;
  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.    
  16.     system("pause");
  17.     return 0;   
  18. }   
複製代碼

TOP

  1. #include <iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.    
  7.    int x =21;
  8.    int y =5;
  9.    
  10.    cout <<"當 x ="<< x <<" ,y ="<< y << "時"<< endl;
  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. }    [code]
複製代碼
[/code]

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3.   using namespace std;

  4.     int main()  
  5. {   
  6.      int x = 21;
  7.      int y= 5;
  8.      
  9.      cout << "當 x = "<<x<< ", y = "<<"時: endl
  10.      cout << " x+y= " << x+y <<endl;
  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.      
  16.      system("pause");
  17.      return 0;
複製代碼

TOP

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

TOP

返回列表