返回列表 發帖

五則運算

本帖最後由 tonyh 於 2013-2-16 15:23 編輯

加, 減, 乘, 除, 取餘數.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x=12, y=5;
  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=12,y=5;
  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.     int x=1,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<< 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=12, y=24;
  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

#include <iostream>
#include<cstdlib>
using namespace std ;
int main()
{
int x=100, y=500;
cout<<"當x的值為"<<x<<"y的值為"<<y<<"時..."<<endl;
cout<<"x+y="<<x+y<<endl;
cout<<"x-y="<<x-y<<endl;
cout<<"x*y="<<x*y<<endl;
cout<<"x/y="<<x/y<<endl;
cout<<"x%y="<<x%y<<endl;
system("pause");
return 0;
}

TOP

#include<iostream>   
#include<cstdlib>
using namespace std;
int main()
{
    int x=123, y=10000000;                     
    cout<<"當x的值為"<<x<<",y的值為"<<y<<"時..."<<endl;
    cout<<"x+y="<<x+y<<endl;
    cout<<"x-y="<<x-y<<endl;
    cout<<"x*y="<<x*y<<endl;
    cout<<"x/y="<<x/y<<endl;
    cout<<"x%y="<<x%y<<endl;
    system("pause");  
    return 0;        
}

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   int x=12,y=5;
  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.    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=12, y=5;
  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.     int a,b;  
  7.     cout<<"請輸入a:"<<endl;
  8.     cin>>a;
  9.     cout<<"請輸入b:"<<endl;
  10.     cin>>b;      
  11.     cout<<"a="<<a<<endl;
  12.     cout<<"b="<<b<<endl;
  13.     cout<<"a+b="<<a+b<<endl;
  14.     cout<<"a-b="<<a-b<<endl;   
  15.     cout<<"a*b="<<a*b<<endl;   
  16.     cout<<"a/b="<<a/b<<endl;   
  17.     cout<<"a%b="<<a%b<<endl; //求a 除以b 的餘數     
  18.     cout<<"Hello!"<<endl;
  19.     system("pause");    //讓畫面暫停
  20.     return 0;           //歸零
  21. }
複製代碼
May

TOP

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

TOP

返回列表