第9章第1讲编译预处理基本形式
#include"stdio.h" #define PI 3.14 main() { float l,s,r; printf("请输入半径:"); scanf("%f",&r); l=2.0*PI*r; s=PI*r*r; printf("l=%.2f s=%.2f\n",l,s); }
#include"stdio.h" #define PI 3.14 #define S(r) PI*r*r main( ) { float r1=1.5,area; area=S(r1); printf("r=%.2f,area=%.2f\n",r1,area); }
#include"stdio.h" #define DEBUG main() { int x,y; x=2; y=3; x*=x+2; y/=y-2; #ifdef DEBUG printf("x=%d,y=%d\n",x,y); #endif printf("x+y=%d\n",x+y); }
#include"stdio.h" #define R 1 main() { char web[50]; int i=0; gets(web); while(web[i]!='\0') { #if(R==1) if(web[i]>='A'&&web[i]<='Z') {web[i]=web[i]+32; i++;} #else if(web[i]>='a'&&web[i]<='z') {web[i]=web[i]-32; i++;} #endif } puts(web); }