#if…#else和#endif命令
#include<stdio.h>
#define pi 3.14159
int main()
{
float r=0;
float s,v=0;
printf("请输入半径r:");
scanf("%f",&r);
#if 0
s=4*pi*r*r;
printf("半径为%f的圆球表面积为:%f\n",r,s);
#endif
v=4*pi*r*r*r/3.0;
printf("半径为%f的圆球体积为:%f\n",r,v);
}
#if…#else…#endif命令
#include<stdio.h>
#define sl 30
#define lc 1
int main()
{
char str[sl]="basic c language study",c;
int i=0;
while((c=str[i]!='\0'))
{
i++;
#if lc
if('A'<=c&&c<='Z')
{
c=c+32;
}
#else
if('a'<=c&&c<='z')
{
c=c-32;
}
#endif
printf("%c",c);
}
printf("\n");
}
#ifdef…#endif和#indef…#endif命令
#include<stdio.h>
#define ency 1
#define max 100
int main()
{
int i=0;
char telegram[max];
printf("请输入电报报文:");
gets(telegram);
#ifdef ency;
for(int i=0;telegram[i]!='\0';i++)
{
if((telegram[i]>='a'&&telegram[i]<='z')||(telegram[i]>='A'&&telegram[i]<='Z'))
{
telegram[i]+=1;
}
else if(('z'==telegram[i])||('Z'==telegram[i]))
{
telegram[i]=telegram[i]-25;
}
}
printf("电报密文为:");
puts(telegram);
printf("\n");
#else
printf("电报报文为:");
puts(telegram);
#endif
}