资源描述
编译预处理部分课堂练习
学号_______________ 姓名_____________ 成绩________________
1. 编写一个程序,定义一个判断字符是大写字母的宏,一个判断字符是小写字母的宏,以及实现大小写字母转换的宏,并将用户输入的一个字符串中的大小写字母互换。
#include <stdio.h>
#define ISUPPER(c) __________________________
#define ISLOWER(c) __________________________
#define CHANGE(c) if(ISUPPER(c)) c+=32; else if(ISLOWER(c)) c-=32;
void main()
{
char s[20];
int i;
printf("输入字符串:");
scanf("%s",s);
for(i=0;s[i];i++)
___________________;
printf("%s",s);
}
2. 编写一个程序,用户输入一个字符串,可以原样输出,也可以逆序输出,使用条件编译的方法加以控制。
#include <stdio.h>
#define CONVERSE
void main()
{
char s[20];
int i=0;
printf("输入字符串:");
scanf("%s",s);
printf("输出结果:");
#ifdef CONVERSE
#else
printf("%s",s);
#endif
}
展开阅读全文