標題:
[想想看] 三數比大小 (考慮所有情況)
[打印本頁]
作者:
鄭繼威
時間:
2023-2-10 01:56
標題:
[想想看] 三數比大小 (考慮所有情況)
本帖最後由 鄭繼威 於 2023-2-17 19:28 編輯
試設計一個小程式, 讓使用者任意輸入三個大小不同的數, 接著電腦回應出這三個數的大小關係由大而小排列出, 包括任兩數相等, 或三數皆相等的情況.
譬如:
當使用者依序輸入5, 12, 3, 電腦會回應 12>5>3
當使用者依序輸入10, 8, 8, 電腦會回應 10>8=8
當使用者依序輸入 7, 7, 7, 電腦會回應 7=7=7
提示: 想一下總共有
13種
情況.
a大
a>b>c
a>c>b
a=b>c
a>c=b
b大
b>a>c
b>c>a
b=c>a
b>c=a
c大
c>a>b
c>b>a
c=a>b
c>b=a
都等於
a=b=c
本帖隱藏的內容需要積分高於 1 才可瀏覽
作者:
何權晉
時間:
2023-2-17 19:43
#include <iostream>;
using namespace std;
int main()
{
int a,b,c;
re:
cout<<"Enter three individual numbers: ";
cin>>a>>b>>c;
if(a>b and a>c)
cout<<a<<">"<<b<<">"<<c<<endl;
else if(a>c and c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
else if (a==b && b>c)
cout<<a<<"="<<b<<">"<<c<<endl;
else if (a>b && a==c)
cout<<a<<">"<<b<<"="<<c<<endl;
else if(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if (b==c && b>a)
cout<<b<<"="<<c<<"<"<<a<<endl;
else if (b<c && b==a)
cout<<b<<"<"<<c<<"="<<a<<endl;
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c==a && a>b)
cout<<c<<"="<<a<<">"<<b<<endl;
else if (c>a && a==b)
cout<<c<<">"<<a<<"="<<b<<endl;
else if (a==b && b==c)
cout<<a<<"="<<b<<"="<<c<<endl;
else
cout<<"information out of reach ...."<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳寶綸
時間:
2023-2-17 19:47
#include <iostream>;
using namespace std;
int main()
{
int a,b,c;
re:
cout<<"Enter three individual numbers: ";
cin>>a>>b>>c;
if(a>b and a>c)
cout<<a<<">"<<b<<">"<<c<<endl;
else if(a>c and c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
else if (a==b && b>c)
cout<<a<<"="<<b<<">"<<c<<endl;
else if (a>b && a==c)
cout<<a<<">"<<b<<"="<<c<<endl;
else if(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if (b==c && b>a)
cout<<b<<"="<<c<<"<"<<a<<endl;
else if (b<c && b==a)
cout<<b<<"<"<<c<<"="<<a<<endl;
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c==a && a>b)
cout<<c<<"="<<a<<">"<<b<<endl;
else if (c>a && a==b)
cout<<c<<">"<<a<<"="<<b<<endl;
else if (a==b && b==c)
cout<<a<<"="<<b<<"="<<c<<endl;
else
cout<<"information out of reach ...."<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡沛倢
時間:
2023-2-17 19:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請隨機輸入三個數字:";
cin>>a>>b>>c;
if (a>b and b>c){
cout<<a<<">"<<b<<">"<<c<<endl; }
else if (a>c and c>b){
cout<<a<<">"<<c<<">"<<b<<endl; }
else if (a>c and c==b){
cout<<a<<">"<<c<<"="<<b<<endl; }
else if (a==b and b>c){
cout<<a<<"="<<b<<">"<<c<<endl; }
else if (b>c and c>a){
cout<<b<<">"<<c<<">"<<a<<endl; }
else if (b>a and a>c){
cout<<b<<">"<<a<<">"<<c<<endl; }
else if (b>c and c==a){
cout<<b<<">"<<c<<"="<<a<<endl; }
else if (b==c and c>a){
cout<<b<<"="<<c<<">"<<a<<endl; }
else if (c>a and a>b){
cout<<c<<">"<<a<<">"<<b<<endl; }
else if (c>b and b>a){
cout<<c<<">"<<b<<">"<<a<<endl; }
else if (c==a and a>b){
cout<<c<<"="<<a<<">"<<b<<endl; }
else if (c>b and b==a){
cout<<c<<">"<<b<<"="<<a<<endl; }
else{
cout<<"你怎麼輸入的??(好問號)"<<endl; }
system("pause");
return 0;
}
複製代碼
作者:
呂得銓
時間:
2023-2-17 19:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請輸入三個數字:";
cin>>a>>b>>c;
if (a>b and b>c){
cout<<a<<">"<<b<<">"<<c<<endl; }
else if (a>c and c>b){
cout<<a<<">"<<c<<">"<<b<<endl; }
else if (a>c and c==b){
cout<<a<<">"<<c<<"="<<b<<endl; }
else if (a==b and b>c){
cout<<a<<"="<<b<<">"<<c<<endl; }
else if (b>c and c>a){
cout<<b<<">"<<c<<">"<<a<<endl; }
else if (b>a and a>c){
cout<<b<<">"<<a<<">"<<c<<endl; }
else if (b>c and c==a){
cout<<b<<">"<<c<<"="<<a<<endl; }
else if (b==c and c>a){
cout<<b<<"="<<c<<">"<<a<<endl; }
else if (c>a and a>b){
cout<<c<<">"<<a<<">"<<b<<endl; }
else if (c>b and b>a){
cout<<c<<">"<<b<<">"<<a<<endl; }
else if (c==a and a>b){
cout<<c<<"="<<a<<">"<<b<<endl; }
else if (c>b and b==a){
cout<<c<<">"<<b<<"="<<a<<endl; }
else{
cout<<"information out of reach ...."<<endl;}
system("pause");
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-2-17 19:59
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c;
re:
cout<<"請任意輸入三個數: ";
cin>>a>>b>>c;
//1
if(a>b and b>c)
cout<<a<<">"<<c<<">"<<b<<endl;
//2
else if(a>c and c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
//3
else if(a==b and b>c)
cout<<a<<"="<<b<<">"<<c<<endl;
//4
else if(a>c and c==b)
cout<<a<<">"<<c<<"="<<b<<c<<endl;
else if(b>a and a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
//5
else if(b>c and c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if(b==c and c>a)
cout<<b<<"="<<c<<">"<<a<<endl;
//5
else if(b>c and c==a)
cout<<b<<">"<<c<<"="<<a<<endl;
//6
else if(c>a and a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
//7
else if(c>b and b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c=b and b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
//7
else if(c>b and b==a)
cout<<c<<">"<<b<<"="<<a<<endl;
//8
else
cout<<a<<"="<<b<<"="<<c<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-2-17 20:03
#include <iostream>;
using namespace std;
int main()
{
int a,b,c;
re:
cout<<"Enter three individual numbers: ";
cin>>a>>b>>c;
if(a>b and a>c)
cout<<a<<">"<<b<<">"<<c<<endl;
else if(a>c and c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
else if (a==b && b>c)
cout<<a<<"="<<b<<">"<<c<<endl;
else if (a>b && a==c)
cout<<a<<">"<<b<<"="<<c<<endl;
else if(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if (b==c && b>a)
cout<<b<<"="<<c<<"<"<<a<<endl;
else if (b<c && b==a)
cout<<b<<"<"<<c<<"="<<a<<endl;
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c==a && a>b)
cout<<c<<"="<<a<<">"<<b<<endl;
else if (c>a && a==b)
cout<<c<<">"<<a<<"="<<b<<endl;
else if (a==b && b==c)
cout<<a<<"="<<b<<"="<<c<<endl;
else
cout<<"information out of reach ...."<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2023-2-17 20:06
6
作者:
曹祁望
時間:
2023-2-17 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請輸入三個數字:";
cin>>a>>b>>c;
if (a>b and b>c){
cout<<a<<">"<<b<<">"<<c<<endl;
}
else if (a>c and c>b){
cout<<a<<">"<<c<<">"<<b<<endl;
}
else if (a>c and c==b){
cout<<a<<">"<<c<<"="<<b<<endl;
}
else if (a==b and b>c){
cout<<a<<"="<<b<<">"<<c<<endl;
}
else if (b>c and c>a){
cout<<b<<">"<<c<<">"<<a<<endl;
}
else if (b>a and a>c){
cout<<b<<">"<<a<<">"<<c<<endl;
}
else if (b>c and c==a){
cout<<b<<">"<<c<<"="<<a<<endl;
}
else if (b==c and c>a){
cout<<b<<"="<<c<<">"<<a<<endl;
}
else if (c>a and a>b){
cout<<c<<">"<<a<<">"<<b<<endl;
}
else if (c>b and b>a){
cout<<c<<">"<<b<<">"<<a<<endl;
}
else if (c==a and a>b){
cout<<c<<"="<<a<<">"<<b<<endl;
}
else if (c>b and b==a){
cout<<c<<">"<<b<<"="<<a<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張桔熙
時間:
2023-2-17 20:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
re:
cout<<"請任意輸入三個數:";
cin>>a>>b>>c;
if(a>b && b>c)
cout<<a<<">"<<b<<">"<<c<<endl;
else if(a>c && c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
else if(a==b && b>c)
cout<<a<<"=="<<b<<">"<<c<<endl;
else if( a>b && a==c )
cout<<a<<"="<<b<<">"<<c<<endl;
else if(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if(b==a && b>a)
cout<<b<<"="<<c<<">"<<a<<endl;
else if(b<c && b==a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c>a && a==b)
cout<<c<<">"<<a<<"="<<b<<endl;
else if(a==b && b==c)
cout<<a<<"="<<b<<"="<<c<<endl;
else
cout<<"不對ㄟ"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
廖秝瑜
時間:
2023-2-19 09:47
#include<iostream>
#include<cstdlib>
使用命名空間標準;
int main()
{
國際 a,b,c;
cout<<“請輸入三個數字:”;
辛>>a>>b>>c;
如果 (a>b 和 b>c){
cout<<a<<“>”<<b<<“>”<<c<<endl;
}
否則如果 (a>c 和 c>b){
cout<<a<<“>”<<c<<“>”<<b<<endl;
}
否則如果 (a>c 和 c==b){
cout<<a<<“>”<<c<<“=”<<b<<endl;
}
否則如果(a==b和b>c){
cout<<a<<“=”<<b<<“>”<<c<<endl;
}
否則如果 (b>c 和 c>a){
cout<<b<<“>”<<c<<“>”<<a<<endl;
}
否則如果 (b>a 和 a>c){
cout<<b<<“>”<<a<<“>”<<c<<endl;
}
否則如果 (b>c 和 c==a){
cout<<b<<“>”<<c<<“=”<<a<<endl;
}
否則如果 (b==c 和 c>a){
cout<<b<<“=”<<c<<“>”<<a<<endl;
}
否則如果 (C>a 和 A>B){
cout<<c<<“>”<<a<<“>”<<b<<endl;
}
否則如果 (c>b 和 b>a){
cout<<c<<“>”<<b<<“>”<<a<<endl;
}
否則如果(c==a和a>b){
cout<<c<<“=”<<a<<“>”<<b<<endl;
}
否則如果 (c>b 和 b==a){
cout<<c<<“>”<<b<<“=”<<a<<endl;
}
系統(「暫停」);
返回 0;
}
複製代碼
作者:
邵凡榛
時間:
2023-2-19 21:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請隨機輸入三個數字:";
cin>>a>>b>>c;
if (a>b and b>c){
cout<<a<<">"<<b<<">"<<c<<endl;}
else if (a>c and c>b){
cout<<a<<">"<<c<<">"<<b<<endl;}
else if (a>b and b==c){
cout<<a<<">"<<b<<"="<<c<<endl;}
else if (a==b and b>c){
cout<<a<<"="<<b<<">"<<c<<endl; }
else if (b>c and c>a){
cout<<b<<">"<<c<<">"<<a<<endl;}
else if (b>a and a>c){
cout<<b<<">"<<a<<">"<<c<<endl;}
else if (b>c and c==a){
cout<<b<<">"<<c<<"="<<a<<endl;}
else if (b==c and c>a){
cout<<b<<"="<<c<<">"<<a<<endl;}
else if (c>a and a>b){
cout<<c<<">"<<a<<">"<<b<<endl;}
else if (c>b and b>a){
cout<<c<<">"<<b<<">"<<a<<endl;}
else if (c==a and a>b){
cout<<c<<"="<<a<<">"<<b<<endl;}
else if (c>b and b==a){
cout<<c<<">"<<b<<"="<<a<<endl;}
else{
cout<<"輸入錯誤"<<endl;}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2