huangblue / c100

0 stars 0 forks source link

第十三章,预处理器 13.2 宏定义展示 #201

Open huangblue opened 7 years ago

huangblue commented 7 years ago

//阅读版本 / Function to calculate the area and circumference of a circle, and the volume of a sphere of a given radius /

include

define PI 3.141592654

double area (double r) {   return PI r r; } double circumference (double r) {   return 2.0 PI r; } double volume (double r) {   return 4.0 / 3.0 PI r r r; }

int main (void) {   double area (double r), circumference (double r),volume (double r);   printf ("radius = 1: %.4f %.4f %.4f\n",area(1.0), circumference(1.0), volume(1.0));   printf ("radius = 4.98: %.4f %.4f %.4f\n",area(4.98), circumference(4.98), volume(4.98));   return 0; }

huangblue commented 7 years ago

//运行版本 / Function to calculate the area and circumference of a circle, and the volume of a sphere of a given radius /

include

define PI 3.141592654

double area (double r) { return PI r r; } double circumference (double r) { return 2.0 PI r; } double volume (double r) { return 4.0 / 3.0 PI r r r; }

int main (void) { double area (double r), circumference (double r),volume (double r); printf ("radius = 1: %.4f %.4f %.4f\n",area(1.0), circumference(1.0), volume(1.0)); printf ("radius = 4.98: %.4f %.4f %.4f\n",area(4.98), circumference(4.98), volume(4.98)); return 0; }

huangblue commented 7 years ago

radius = 1: 3.1416 6.2832 4.1888 radius = 4.98: 77.9128 31.2903 517.3407

Process returned 0 (0x0) execution time : 0.013 s Press any key to continue.