標題:
三數比大小 (不考慮兩數或三數相等的情況)
[打印本頁]
作者:
鄭繼威
時間:
2022-10-29 01:48
標題:
三數比大小 (不考慮兩數或三數相等的情況)
本帖最後由 鄭繼威 於 2022-10-29 15:00 編輯
試設計一個小程式, 讓使用者任意輸入三個數, 接著電腦回應出這三個數的大小順序, 由大而小排列出.
譬如:
當使用者依序輸入5, 12, 3, 電腦會回應 "12>5>3"
當使用者依序輸入7, 2, 11, 電腦會回應 "11>7>2"
當使用者依序輸入7, 7, 11, 電腦會回應 "其中兩個數, 或三個數相等!"
提示: 總共有
6種
情況.
a大
a>b>c
a>c>b
b大
b>a>c
b>c>a
c大
c>a>b
c>b>a
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c;
re:
cout<<"請任意輸入三個數: ";
cin>>a>>b>>c;
//a大
//a>b>c
if(a>b && b>c)
cout<<a<<">"<<b<<">"<<c<<endl;
//a>c>b
else if(a>c && c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
//b大
//b>a>c
else if(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
//b>c>a
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
//c大
//c>a>b
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
//c>b>a
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
//其他狀況
else
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
盧禹丞
時間:
2022-10-29 11:41
#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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>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
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
吳俊頡
時間:
2022-10-29 13:08
#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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>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
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
徐啟祐
時間:
2022-10-29 13:44
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
int a,b,c;
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(b>a&&a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c&&c>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
cout<<"其中有兩數, 或三個數相等!"<<endl;
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
宜儒
時間:
2022-10-29 14:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a,b,c;
cout<<"請輸入任意三數字"<<endl;
cin>>a>>b>>c;
if(a>b&&b>c){
cout<<a<<">"<<b<<">"<<c<<endl;
}
else if(a>c&&a>b){
cout<<a<<">"<<c<<">"<<b<<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(c>a&&a>b){
cout<<c<<">"<<a<<">"<<b<<endl;
}
else if(c>b&&b>a){
cout<<c<<">"<<b<<">"<<a<<endl;
}
else{
cout<<"有兩數或三數相等"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
陳宥霖
時間:
2022-10-29 14:11
#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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>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
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2022-10-29 15:06
以上5位同學OK
作者:
黃品禎
時間:
2022-10-29 15:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"請輸入任意3個數:"<<endl;
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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>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
cout<<"其中有兩個數,或三個數箱等!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
羅紹齊
時間:
2022-10-29 15:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a,b,c;
cout<<"輸入a:";
cin>>a;
cout<<"輸入b:";
cin>>b;
cout<<"輸入c:";
cin>>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(b>a and a>c){
cout<<"b>a>c"<<endl;
}
else if(b>c and c>a){
cout<<"b>c>a"<<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
cout<<"兩數或三數相等"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳牧謙
時間:
2022-10-29 15:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c;
re:
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(b>a and a>c)
cout<<b<<">"<<a<<">"<<c<<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
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
林雋喆
時間:
2022-10-29 15:10
#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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>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
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
楊芊琦
時間:
2022-10-29 15:10
本帖最後由 楊芊琦 於 2022-10-29 15:13 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a,b,c;
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(b>a and a>c)
{
cout<<b<<">"<<a<<">"<<c<<endl;
}
else if(b>c and c>a)
{
cout<<b<<">"<<c<<">"<<a<<endl;
}
else if(c>a and a>b)
{
cout<<b<<">"<<a<<">"<<c<<endl;
}
else if(c>b and b>a)
{
cout<<c<<">"<<b<<">"<<a<<endl;
}else if(c>a and a>c)
{
cout<<c<<">"<<a<<">"<<b<<endl;
}
else
{
cout<<"內有相等數,電腦懶得數"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
羅暐傑
時間:
2022-10-29 15:11
#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 (b>a and a>c)
cout<<b<<">"<<a<<">"<<c<<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
cout<<"其中兩個數, 或三個數相等!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2022-10-29 15:12
以上10位同學OK
作者:
葉佳和
時間:
2022-10-29 15:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c;
re:
cout<<"請任意輸入三個數: ";
cin>>a>>b>>c;
if(a>b and a>c){
if(c>b){
cout<<a<<">"<<c<<">"<<b<<endl;
}
else if(c<b){
cout<<a<<">"<<b<<">"<<c<<endl;
}
else{
cout<<a<<">"<<c<<">"<<b<<endl;
}
}
else if(b>a and b>c){
if(c>b){
cout<<b<<">"<<c<<">"<<a<<endl;
}
else if(c<b){
cout<<b<<">"<<a<<">"<<c<<endl;
}
else {
cout<<b<<">"<<c<<"="<<a<<endl;
}
}
else if(c>a and c>b){
if(a>b){
cout<<c<<">"<<a<<">"<<b<<endl;
}
else if(b>a){
cout<<c<<">"<<b<<">"<<a<<endl;
}
else{
cout<<c<<">"<<a<<"="<<b<<endl;
}
}
else{
cout<<a<<"="<<b<<"="<<b<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳泓亦
時間:
2022-10-29 15:15
#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(b>a && a>c)
cout<<b<<">"<<a<<">"<<c<<endl;
else if(b>c && c>a)
cout<<b<<">"<<c<<">"<<a<<endl;
else if(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
else if(c>a && a>b)
cout<<c<<">"<<a<<">"<<b<<endl;
else
cout<<"其中兩個數, 或三個數相等!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
翁川祐
時間:
2022-10-30 16:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a,b,c;
cout<<"請輸入任意三數字"<<endl;
cin>>a>>b>>c;
if(a>b and b>c){
cout<<a<<">"<<b<<">"<<c<<endl;
}
else if(a>c and a>b){
cout<<a<<">"<<c<<">"<<b<<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(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-12-11 19:42
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c;
re:
cout<<"請任意輸入三個數: ";
cin>>a>>b>>c;
if(a>b and b>c)
cout<<a<<">"<<b<<">"<<c<<endl;
// if(a==b and b>c)
// cout<<a<<"="<<b<<">"<<c<<endl;
else if(a>c && c>b)
cout<<a<<">"<<c<<">"<<b<<endl;
// else if(a>c && c==b)
// cout<<a<<">"<<c<<"="<<b<<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(b>c and c==a)
// cout<<b<<">"<<c<<"="<<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(c>b && b>a)
cout<<c<<">"<<b<<">"<<a<<endl;
// else if(c>b && b==a)
// cout<<c<<">"<<b<<"="<<a<<endl;
else
cout<<"其中兩個數, 或三個數相等"<<endl;
cout<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2