[問題] ?: 運算子求三變數中最小值
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Visual Studio C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
要輸入 a,b,c 3值
經過程式運行後,要得出3值中最小值
限定只能使用?:
餵入的資料(Input):
預期的正確結果(Expected Output):
輸入 a,b,c三值,然後求出最小值
錯誤結果(Wrong Output):
輸入了值,但是不會動,隨後跳出錯誤訊息
assign_num: if ( integer64 )*(__int64 UNALIGNED *)pointer = (unsigned
__int64)num64;
else if (longone)*(long UNALIGNED *)pointer = (unsigned
long)number;
else *(short UNALIGNED *)pointer = (unsigned short)number;
}
else /*NULL*/;
elsegoto
error_return;
break;
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a,b,c,x,y;
scanf("%d%d%d",&a,&b,&c);
x = (a>b) ? b : a;
y = (x>c) ? c : x;
printf("三 數為a=%d,b=%d,c=%d,最小值為%d\n",a,b,c,y);
system("pause");return(0);
補充說明(Supplement):
因為還在剛接觸程式語言,找了類題是要限制使用 ?: 來做出求最小值的語言.
我如果在前面先設定a,b,c的值的話是可以跑得,可是設定成scanf之後就跑出錯誤訊息了
麻煩各位專業的大大教教我,不知道哪裡有問題,謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.240.238.168
→
01/24 21:09, , 1F
01/24 21:09, 1F
→
01/24 22:07, , 2F
01/24 22:07, 2F
→
01/25 10:24, , 3F
01/25 10:24, 3F
→
01/25 10:24, , 4F
01/25 10:24, 4F
推
01/25 16:14, , 5F
01/25 16:14, 5F
→
01/25 16:14, , 6F
01/25 16:14, 6F
→
01/25 16:15, , 7F
01/25 16:15, 7F
→
01/25 16:15, , 8F
01/25 16:15, 8F
→
01/25 16:16, , 9F
01/25 16:16, 9F
→
01/25 16:52, , 10F
01/25 16:52, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章