返回列表 發帖

三數中找出最大的數

本帖最後由 陳品肇 於 2019-5-18 10:51 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    re:
  7.    int a,b,c,max;
  8.    cout<<"請依序輸入三個數字:";
  9.    cin>>a>>b>>c;

  10.    max = (a>b)?a:b; //如果a>b 就回傳a否則回傳b
  11.    max = (max>c)?max:c;
  12.    cout<<max<<endl;

  13.    
  14.    goto re;
  15.    system("pause");
  16.    return 0;

  17. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b,c,d,e;
  7.     cout<<"請輸入3個整數: ";
  8.     cin>>a>>b>>c;
  9.    
  10.     d=a>b?a:b;
  11.     e=d>c?d:c;
  12.     cout<<"最大的數為: "<<e<<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.    re:
  7.    int a,b,c,max;
  8.    cout<<"請依序輸入三個數字:";
  9.    cin>>a>>b>>c;

  10.    max = (a>b)?a:b;
  11.    max = (max>c)?max:c;
  12.    cout<<max<<endl;

  13.    
  14.    goto re;
  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,y,z,max;
  7.    
  8.          cout<<"請輸入三個值:";
  9.          cin>>x>>y>>z;
  10.          max=(x>y)?x:y;
  11.          max=(max>z)?max:z;
  12.          cout<<max<<endl;
  13.    
  14.    
  15.    
  16.    
  17.    
  18.    
  19.    
  20.    
  21.    
  22.    
  23.     system("pause");
  24.     return 0;
  25.         
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int a,b,c,max;
  7.    cout<<"請依序輸入三個數字並按enter:";
  8.   cin>>a>>b>>c;
  9.    max = (a>b)?a:b;
  10.    max = (max>c)?max:c;
  11.    
  12.    cout<<max<<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,c,d;
  7.    cout<<"請輸入三個數字:"<<endl;
  8.    cin>>a>>b>>c;
  9.    d = (a>b)?a:b;
  10.    d = (d>c)?d:c;
  11.    cout<<d<<"比較大"<<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 a,b,c,max;
  7.     cout<<"請輸入三個數";
  8.     cin>>a>>b>>c;
  9.     max= (a>b)?a:b;
  10.     max= (max>c)?max:c;
  11.     cout<<max<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int a,s,t,z;
  8.     cout<<"請輸入三個數:"<<endl;
  9.     cin>>a>>s>>t;
  10.     z =(a>s)?a:s;
  11.     z =(z>t)?z:t;
  12.     cout<<z<<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,c,num;
  7.     cout<<"請輸入三個數字:";
  8.     cin>>a>>b>>c;
  9.     num = (a>b)?a:b;
  10.     num = (num>c)?num:c;
  11.     cout<<num<<endl;;
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

TOP

返回列表