[問題] C 語言考題請教
各位好
我看不出來以下兩個 function 有什麼不同,請各位指教。
1.Do cmp1 and cmp2 print the same message for all possible inputs?
if not , please provide a case where they print it.
1.Do cmp1 and cmp2 return the same value for all possible inputs?
if not , please provide a case where they return it.
#define ABS(n) ((n<0)? -n:n)
int cmp1(int a , int b)
{
int result;
a=(a<0) ? -a: a;
b=(b<0) ? -b: b;
result=(a==b);
if(result)
printf("The absolute values of %d and %d are the same.",a,b);
else
printf("The absolute values of %d and %d are different.",a,b);
return result;
}
int cmp2(int a , int b)
{
int result=(ABS(a)==ABS(b));
if(result)
printf("The absolute values of %d and %d are the same.",a,b);
else
printf("The absolute values of %d and %d are different.",a,b);
return result;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.61.144.4 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1705336433.A.C84.html
推
01/16 00:44,
10月前
, 1F
01/16 00:44, 1F
推
01/16 00:59,
10月前
, 2F
01/16 00:59, 2F
→
01/16 00:59,
10月前
, 3F
01/16 00:59, 3F
推
01/16 09:06,
10月前
, 4F
01/16 09:06, 4F
→
01/16 09:06,
10月前
, 5F
01/16 09:06, 5F
→
01/16 09:09,
10月前
, 6F
01/16 09:09, 6F
→
01/16 09:09,
10月前
, 7F
01/16 09:09, 7F
推
01/16 10:18,
10月前
, 8F
01/16 10:18, 8F
→
01/16 10:18,
10月前
, 9F
01/16 10:18, 9F
→
01/16 10:18,
10月前
, 10F
01/16 10:18, 10F
→
01/16 20:05,
10月前
, 11F
01/16 20:05, 11F
推
01/17 14:11,
10月前
, 12F
01/17 14:11, 12F
→
01/17 23:52,
10月前
, 13F
01/17 23:52, 13F
推
01/18 00:12,
10月前
, 14F
01/18 00:12, 14F
推
01/18 05:21,
10月前
, 15F
01/18 05:21, 15F
→
01/18 05:24,
10月前
, 16F
01/18 05:24, 16F
→
01/18 05:25,
10月前
, 17F
01/18 05:25, 17F
→
01/18 07:35,
10月前
, 18F
01/18 07:35, 18F
→
01/18 07:35,
10月前
, 19F
01/18 07:35, 19F
推
01/18 23:08,
10月前
, 20F
01/18 23:08, 20F
→
01/18 23:52,
10月前
, 21F
01/18 23:52, 21F
推
01/20 15:34,
10月前
, 22F
01/20 15:34, 22F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章