新知
- ascii 码记忆,利用字符达到ascii码效果
0 - 9 ascii 是 48-57
‘A’ - ‘Z’ ascii 是 65-90
‘a’ - ‘Z’ ascii 是 97-122 - switch case 的常量表达式的可取类型
switch的case 常量表达式的 值 必须要是整数,因为只有整数才可以列举 ,故可以是 整型、char 型、枚举类型。
case 9:
case ‘A’: - ‘\n’占用一个字节。
练习根据ascii码
练习:
从键盘输入一个字符
如果是小写字母则把它转成对应的大写字母
如果是大写字母则把它转成对应的小写字母
如果是数字,就不改变
然后输出
其它的不处理,也不输出
int main()
{
char test ;
scanf("%c", &test);
if (test >= 65 && test <= 90)
printf("%c\n", test + 32);
else if (test >= 97 && test <= 122)
printf("%c\n", test - 32);
else if (test >= 48 && test <= 57)
printf("%c\n", test);
else
;
}
int main()
{
char test ;
scanf("%c", &test);
if (test >= 'A' && test <= 'Z')
printf("%c\n", test + 32);
else if (test >= 'a' && test <= 'z')
printf("%c\n", test - 32);
else if (test >= '0' && test <= '9')
printf("%c\n", test);
else
printf("unknow\n");
}
请你写一个程序判断7是否是质数
int main()
{
int i;
int a;
scanf("%d", &a);
for (i = 2; i < a; i++)
{
if (a % i == 0)
{
printf("不是质数\n");
break;
}
}
if(i == a)
printf("是质数\n");
}