#define PI 3.1415926 //定义符号常量PI代表为3.1415926
#include <stdio.h>
#include <math.h> //调用pow函数必须包含math.h头文件
int main()
{
double r = 3.66, c, s, v;
c = 2*PI*r;
s = PI*pow(r,2);
v = 4.0/3.0*PI*pow(r,3);
printf("c=%f\ns=%f\nv=%f\n", c, s, v);
return 0;
}
代码运行结果如下:
程序分析:在改良版圆周率可以用符号常量来代替PI(#define PI 3.1415926),在本程序中还运用到了函数pow在使用函数pow必须加上头文件math.h。