作者magicken (追尋酸甜的片段)
看板NTUEE108HW
標題計程C++ 關於if&else if
時間Tue Oct 19 23:51:53 2004
就是三個數字比大小的問題
else if本雞會用了^^
可是....if....(把a b c 關係全列出來的)
會有問題(麻煩看倌對以下的碼輸入 5 8 1測試)
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int a;
int b;
int c;
int d;
int e;
int f;
cout << " Input three different intergers: \n";
cin >> a>>b>>c;
d=a+b+c;
f=a*b*c;
if (a<b<c)
{
cout << "Smallest is =" << a << endl;
cout << "Largest is =" << c <<endl;}
else if (a<c<b)
{
cout << "Smallest is =" << a <<endl;
cout << "Largest is =" <<b<<endl;}
else if (b<a<c)
{
cout << "Smallest is =" <<b<<endl;
cout << "Largest is =" <<c<<endl;}
else if (b<c<a)
{
cout << "Smallest is =" <<b<<endl;
cout << "Largest is =" <<a<<endl;}
else if (c<a<b)
{
cout << "Smallest is =" <<c<<endl;
cout << "Largest is =" <<b<<endl;}
else if (c<b<a)
{
cout << "Smallest is =" <<c<<endl;
cout << "Largest is =" <<a<<endl;}
return 0;
}
--
就是降了 感謝您幫一隻小雞解惑^^
--
靜靜的看著你是現在的我最大的快樂
雖然我從不承認但對你我願意付出我的一切
或許這是前世的冤孽讓我如此痛苦
但我並不敢奢求太多
只希望我們兩個能永遠在一起
不論發生了什麼事..........
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.249.217
推 pg30123:建議使用if(a<=b && a<=c) 210.85.17.1 10/19
推 magicken:喔^^ 如果不唸ㄐㄧㄝˊ 要唸什麼啊? 140.112.249.217 10/20