这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static const int PI = 3.14159; // Defined global constant for PI
int areaR;
int circumferenceR;
int areaD;
int circumferenceD;
int main(void)
{
#define radius 6
#define diameter 12
areaR = PI * pow(radius, 2);
circumferenceR = 2 * PI * radius;
areaD = PI * pow(diameter, 2)) / 4;
circumferenceD = PI * diameter;
puts("Results given a circle of radius 6 and diameter 12:\n");
printf("areaR is %d\n", areaR);
printf("circumferenceR is %d\n", circumferenceR);
printf("areaD is %d\n", areaD);
printf("circumferenceD is %d\n", circumferenceD);
}
这应该输出面积和周长的值,面积约等于 113,周长约等于 37。除此之外,我的输出显示的值不正确,面积为 108,周长为 36。我知道这些值是错误的,但仅比它们应该的值略小。这是我在 C 中的第一个程序,我不确定我哪里出错了。