返回列表 發帖

[隨堂測驗] 五則運算 (二)

如果我們要使用 cin 讓使用者能自行指定 x 與 y 的值要怎麼打呢?

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

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

  4. int main()
  5. {   
  6.     int x,y;
  7.     cout<<"請輸入x;"<<endl;
  8.     cin>>x;
  9.     cout<<"請輸入y;"<<endl;
  10.     cin>>y;   
  11.    
  12.    
  13.     cout<<"當x等於"<<x<<"y等於"<<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.     cout<<"x%y="<<x%y<<endl;
  19.    
  20.     system("pause");
  21.     return 0;
  22. }
複製代碼
[/code]

TOP

#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
    int x,y;
    cout<<"請輸入x:"<<endl;
    cin>>x;
    cout<<"請輸入y:"<<endl;
    cin>>y;
    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,y;
  7.    
  8.     cout<<"請輸入 X:"<<endl;
  9.     cin>>x;
  10.     cout<<"請輸入 y:"<<endl;
  11.     cin>>y;
  12.    
  13.    
  14.    
  15.     cout<<"當x等於"<<x<<",y等於"<<y<<endl;
  16.     cout<<"X+Y="<<x+y<<endl;
  17.     cout<<"X-Y="<<x-y<<endl;
  18.     cout<<"X*Y="<<x*y<<endl;
  19.     cout<<"X/Y="<<x/y<<endl;
  20.     cout<<"X%Y="<<x%y<<endl;
  21.    
  22.     system("pause");
  23.     return 0;
  24. }
複製代碼

TOP

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

  4. int main()
  5. {
  6.     int a,j;
  7.     cout<<"請輸入a"<<endl;
  8.     cin>>a;
  9.     cout<<"請輸入j"<<endl;
  10.     cin>>j;
  11.     cout<<"當a等於"<<a<<",當j等於七時..."<<j<<endl;
  12.     cout<<"a+j="<<a+j<<endl;
  13.     cout<<"a-j="<<a-j<<endl;
  14.     cout<<"a*j="<<a*j<<endl;
  15.     cout<<"a/j="<<a/j<<endl;
  16.     cout<<"a%j="<<a%j<<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,y;
  7.     cout<<"請輸入X的值:"<<endl;
  8.     cin>>x;
  9.     cout<<"請輸入Y的值:"<<endl;
  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,y;
  7.      cout<<"請輸入x:"<<endl;
  8.      cin>>x>>endl;
  9.      cout<<"請輸入y:"<<endl;
  10.      cin>>y>>endl;
  11.      
  12.      
  13.      cout<<"當x等於"<<x<<"y等於"<<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.       cout<<"x%y等於"<<x%y<<endl;
  19.      system("pause")
  20.      return 0;
  21. }     
  22.       
複製代碼

TOP

#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
    int x,y;
    cout<<"請輸入x"<<endl;
    cin>>x;
    cout<<"請輸入y"<<endl;
    cin>>y;
   
   
    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,y;
  7.     cout<<"請輸入x:"<<endl;
  8.     cin>>x;
  9.     cout<<"請輸入y:"<<endl;
  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. }
  20.      
複製代碼

TOP

返回列表