Board logo

標題: [作業1] 三數比大小 (不考慮兩數或三數相等的情況) [打印本頁]

作者: tonyh    時間: 2019-7-13 11:49     標題: [作業1] 三數比大小 (不考慮兩數或三數相等的情況)

本帖最後由 tonyh 於 2019-7-13 11:57 編輯

試設計一個小程式, 讓使用者任意輸入三個數, 接著電腦回應出這三個數的大小順序, 由大而小排列出.
譬如:
當使用者依序輸入5, 12, 3, 電腦會回應 "12>5>3"
當使用者依序輸入7, 2, 11, 電腦會回應 "11>7>2"
當使用者依序輸入7, 7, 11, 電腦會回應 "其中兩個數, 或三個數相等!"


作者: 郭哲維    時間: 2019-7-19 11:49

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int a,b,c;
  8.     cout<<"請任意輸入三個數: ";
  9.     cin>>a>>b>>c;
  10.     if(a>b && b>c)
  11.     {
  12.         cout<<a<<">"<<b<<">"<<c<<endl;
  13.     }else if(a>c && c>b)
  14.     {
  15.         cout<<a<<">"<<c<<">"<<b<<endl;
  16.     }else if(b>a && a>c)
  17.     {
  18.         cout<<b<<">"<<a<<">"<<c<<endl;
  19.     }else if(b>c && c>a)
  20.     {
  21.         cout<<b<<">"<<c<<">"<<a<<endl;
  22.     }else if(c>a && a>b)
  23.     {
  24.         cout<<c<<">"<<a<<">"<<b<<endl;
  25.     }else if(c>b && b>a)
  26.     {
  27.         cout<<c<<">"<<b<<">"<<a<<endl;
  28.     }else
  29.         cout<<"其中兩個數,或三個數相等!"<<endl;
  30.     goto re;
  31.     system("pause");
  32.     return 0;
  33. }
複製代碼

作者: 王翎璇    時間: 2019-7-19 17:57

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int a,b,c;
  8.     cout<<"請任意輸入三個數: ";
  9.     cin>>a>>b>>c;
  10.     if(a<b && b<c)
  11.     {
  12.             cout<<a<<"<"<<b<<"<"<<c<<endl;
  13.         }
  14.         else if(a<c && c<b)
  15.     {
  16.             cout<<a<<"<"<<c<<"<"<<b<<endl;
  17.         }
  18.         else if(b<a && a<c)
  19.     {
  20.             cout<<b<<"<"<<a<<"<"<<c<<endl;
  21.         }
  22.         else if(b<c && c<a)
  23.     {
  24.             cout<<b<<"<"<<c<<"<"<<a<<endl;
  25.         }
  26.         else if(c<a && a<b)
  27.     {
  28.             cout<<c<<"<"<<a<<"<"<<b<<endl;
  29.         }
  30.         else if(c<b && b<a)
  31.     {
  32.             cout<<c<<"<"<<b<<"<"<<a<<endl;
  33.         }
  34.         else
  35.         {
  36.                 cout<<"其中兩個數, 或三個數相等!"<<endl;
  37.         }
  38.     goto re;
  39.     system("pause");
  40.     return 0;
  41. }
複製代碼

作者: 蔡少宇    時間: 2019-7-19 19:42

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         re:
  7.         int a,b,c;
  8.         cout<<"請任意輸入三個數字: ";
  9.         cin>>a>>b>>c;
  10.         if(a>b && b>c)
  11.         {
  12.                 cout<,a<<">"<<b<<">"<<c<<endl;
  13.         }else if(a>c && c>d)
  14.         {
  15.                 cout<<a<<">"<<c<<">"<<b<<endl;
  16.         }else if(b>a && a>c)
  17.         {
  18.                 cout<<b<<">"<<a<<">"<<c<<endl;
  19.         }else if(b>c && c>a)
  20.         {
  21.                 cout<<b<<">"<<c<<>">"<<a<<endl;
  22.         }else if(c>a && a>b)
  23.         {
  24.                 cout<<c<<">"<<a<<">"<<b<<endl;
  25.         }else if(c>d && b>a)
  26.         {
  27.                 cout<<c<<">"<<b<<">"<<a<<endl;
  28.         }else
  29.             cout<<"其中兩個數,或三個數相等!"<<endl;
  30.         goto re:
  31.         system("pause");
  32.         return 0;
  33. }
複製代碼

作者: 曾宥程    時間: 2019-7-19 21:17

本帖最後由 曾宥程 於 2019-7-20 10:40 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         re:
  7.         int x,y,z;
  8.         cout<<"請輸入三個數: ";
  9.         cin>>x>>y>>z;
  10.         if(x>y && y>z)
  11.             cout<<x<<">"<<y<<">"<<z<<endl;
  12.         else if(x>z && z>y)
  13.             cout<<x<<">"<<z<<">"<<y<<endl;
  14.         else if(y>x && x>z)
  15.             cout<<y<<">"<<x<<">"<<z<<endl;
  16.         else if(y>z && z>x)
  17.             cout<<y<<">"<<z<<">"<<x<<endl;
  18.         else if(z>x && x>y)
  19.             cout<<z<<">"<<x<<">"<<y<<endl;
  20.         else if(z>y && y>x)
  21.             cout<<z<<">"<<y<<">"<<x<<endl;
  22.         else
  23.             cout<<"其中兩個數, 或三個數相等!"<<endl;
  24.         goto re;      
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

作者: 劉愷恩    時間: 2019-7-19 21:26

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         re:
  7.         int a,b,c;
  8.         cout<<"請輸入三個數:";
  9.         cin>>a>>b>>c;
  10.        
  11.         if(a>b && b>c)
  12.             cout<<a<<">"<<b<<">"<<c<<endl;
  13.         else if(a>c && c>b)
  14.             cout<<a<<">"<<c<<">"<<b<<endl;   
  15.         else if(b>a && a>c)
  16.             cout<<b<<">"<<a<<">"<<c<<endl;
  17.         else if(b>c && c>a)
  18.             cout<<b<<">"<<c<<">"<<a<<endl;
  19.         else if(c>a && a>b)
  20.             cout<<c<<">"<<a<<">"<<b<<endl;
  21.         else if(c>b && b>a)
  22.             cout<<c<<">"<<b<<">"<<a<<endl;
  23.         else
  24.             cout<<"其中兩個數, 或三個數相等!"<<endl;
  25.         cout<<endl;
  26.         goto re;
  27.        
  28.         system("pause");
  29.         return 0;
  30. }
複製代碼

作者: 鄭羽捷    時間: 2019-7-19 22:09

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         re:
  7.         int a,b,c;
  8.         cout<<"請任意輸入三個數:";
  9.         cin>>a>>b>>c;
  10.         if(a>b && b>c)
  11.         {
  12.                 cout<<a<<">"<<b<<">"<<c<<endl;
  13.         }
  14.         else if(a>c && c>b)
  15.         {
  16.                 cout<<a<<">"<<c<<">"<<b<<endl;
  17.         }
  18.         else if(b>a && a>c)
  19.         {
  20.                 cout<<b<<">"<<a<<">"<<c<<endl;
  21.         }
  22.         else if(b>c && c>a)
  23.         {
  24.                 cout<<b<<">"<<c<<">"<<a<<endl;
  25.         }
  26.         else if(c>a && a>b)
  27.         {
  28.                 cout<<c<<">"<<a<<">"<<b<<endl;
  29.         }
  30.         else if(c>b && b>a)
  31.         {
  32.                 cout<<c<<">"<<b<<">"<<a<<endl;
  33.     }
  34.         else
  35.                 cout<<"其中兩個數, 或三個數相等!"<<endl;
  36.         goto re;
  37.         system("pause");
  38.     return 0;
  39. }
複製代碼

作者: 林孟蓁    時間: 2019-7-19 23:26

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. re:
  7.         
  8.         int a,b,c;
  9.         cout<<"請任意輸入3個數: ";
  10.         cin>>a>>b>>c;

  11.         if(a>b && b>c)
  12.         {
  13.         cout<<a<<">"<<b<<">"<<c<<endl;
  14.                 }
  15.                 else if(a>c && c>b)
  16.         {
  17.             cout<<a<<">"<<c<<">"<<b<<endl;
  18.         }
  19.         else if(b>a && a>c)
  20.         {
  21.             cout<<b<<">"<<a<<">"<<c<<endl;
  22.         }
  23.         else if(b>c && c>a)
  24.         {
  25.             cout<<b<<">"<<c<<">"<<a<<endl;   
  26.                 }
  27.                 else if(c>a && a>b)
  28.                 {
  29.                         cout<<c<<">"<<a<<">"<<b<<endl;
  30.         }
  31.         else if(c>b && b>a)
  32.         {
  33.                 cout<<c<<">"<<b<<">"<<a<<endl;
  34.             }
  35.             else
  36.                 cout<<"其中兩個數,或三個數相等! "<<endl;
  37.     cout<<endl;
  38.     goto re;
  39.     system("pause");
  40.     return 0;
  41. }
複製代碼

作者: 駱顗安    時間: 2020-6-11 16:14

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b,c,d;
  7.     int n=3;
  8.     cout<<"請任意輸入三個數:";
  9.     cin>>a>>b>>c;
  10.     cout<<endl;
  11.     if(a==b||b==c||c==a)
  12.     cout<<"其中兩個數, 或三個數相等!";
  13.     else
  14.     {
  15.          for(int m=a+b+c;m>=0;m-=1)
  16.          if(m==a)
  17.          {
  18.                  n=n-1;
  19.                  cout<<a;
  20.                  if(n>=1)
  21.                  cout<<">";
  22.                  else
  23.                  cout<<" ";
  24.          }
  25.          else if(m==b)
  26.          {
  27.                  n=n-1;
  28.                  cout<<b;
  29.                  if(n>=1)
  30.                  cout<<">";
  31.                  else
  32.                  cout<<" ";
  33.          }
  34.          else if(m==c)
  35.          {
  36.                  n=n-1;
  37.                  cout<<c;
  38.                  if(n>=1)
  39.                  cout<<">";
  40.                  else
  41.                  cout<<" ";
  42.          }
  43.     }
  44.     system("pause");
  45.     return 0;
  46. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2