返回列表 發帖

五則運算

本帖最後由 tonyh 於 2015-1-30 11:08 編輯

加, 減, 乘, 除, 取餘數
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x=5, y=2;  //宣告整數型態的變數x與y初始值分別為5與2
  7.     cout<<"當x的值為"<<x<<",y的值為"<<y<<"時..."<<endl;
  8.     cout<<"x+y="<<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.     system("pause");
  14.     return 0;   
  15. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.       int x=5,y=2;
  7.       
  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=23,y=7;
  7.     cout<<"當x的值為"<<x<<",當y的值為"<<y<<"時..."<<endl;
  8.     cout<<"X+Y="<<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.     system("pause");   
  14.     return 0;           
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int x=5,y=2 //宣告兩個整數變數,並指定他們的值
  8.    
  9.     cout<<"當x的值為"<<x<<",y的值為"<<y<<"時"..."<<endi;
  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=23,y=7;
  7.     cout<<"當x的值為"<<x<<",y的值為"<<y<<"時..."<<endl;
  8.     cout<<"x+y="<<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.    
  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=5, y=2;
  7.     cout<<"x是"<<x<<",y是"<<y<<endl;
  8.     cout<<"x+y="<<x+y<<endl;
  9.     cout<<"x-y="<<x-y<<endl;
  10.     cout<<"x*y="<<x*y<<endl;
  11.     cout<<"x/y="<<x/y<<"..."<<x%y<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int x=23,y=7;
  7.    
  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=23,y=7;
  7.     cout<<"當x的值為"<<x<<",y的值為"<<y<<"時..."<<endl;
  8.     cout<<"x+y="<<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.    
  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=23,y=7;
  7.      
  8.   cout<<"x+y="<<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.    system("pause");
  14.    return 0;
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int x=23,y=7;
  7.    
  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=23,y=7;
  7.    
  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.    
  18.    
  19.    
  20. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     //五則運算

  7.     int x=23,y=7;      
  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.        cout<<"555"<<endl;
  17.     system("pause");
  18.     return 0;   
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.        int x=23,y=7;
  7.        cout<<"x+y="<<x+y<<endl;
  8.        cout<<"x-y="<<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.        system("pause");
  13.        return 0;
  14.    
  15. }
複製代碼

TOP

回復 13# 許博竣
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int x=7,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.     cout<<"hello"<<endl;
  7.     system("pause");
  8.     return 0;
  9. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x=23,y=7;
  7.    
  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;   
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int  main()
  5. {
  6.      //五則運算
  7.      int x=5,y=2;
  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. { int x=23, y=7;
  6.     cout<<"當x的值為"<<x<<",y的值為"<<y<<"時..."<<endl;
  7.      cout<<"x+y="<<x+y<<endl;
  8.    cout<<"x-y="<<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.    
  13.    system("pause");
  14.    return 0;
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    cout<<"算算看"<<endl;
  7.    int x=2056, y=28;
  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;
  7.    
  8.     cout<<"請輸入正方形長度(公分):";
  9.     cin>>x;
  10.     cout<<"請輸入正方形長度(公分):";
  11.     cin>>x;
  12.     cout<< "這個正方形的周長為:公分"<<x+x+x+x<<endl;
  13.    
  14.     system("pause");
  15.     return 0;  
  16. }
複製代碼

TOP

返回列表