#include <stdio.h>
#include <stdlib.h>
#define calc(a,b) (a*b)/(a-b)
void calculate(){
int a = 20, b = 10;
printf("%f\n", calc(a+4,b-2));//output 0.00000
}
如何打印实际答案,4.83。
最佳答案
#define calc(a,b) ((a)*(b))/((a)-(b))
你能找出多余的括号吗?
--> calc(a+4,b-2)
解析为 ((a+4)*(b-2))/((a+4)-( b-2))
。正确。
没有额外括号的解决方案:
--> calc(a+4,b-2)
解析为(a+4*b-2)/(a+4-b-2)
。这是非常不同的!
关于c - 哪个格式说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084573/