机试训练-ZZULIOJ 1023-1032(C语言)
2020-04-07 12:17
2116 查看
20200318(1023-1032)
输入一个字母,若是小写字母,则变为大写输出,否则,原样输出。看清题目呀
#include <stdio.h> #include <string.h> void main() { char s1,s; scanf("%c",&s1); if(s1>='A'&& s1<='Z') { printf("%c\n",s1); } else if(s1 >='a' && s1 <='z') { s=s1-32; //a变成A是减!! printf("%c\n",s); } }
大写变小写是加哟
字符类型判断
/*从键盘输入一个字符,判断该字符是否大写字母、小写字母、 数字字符或其他字符。分别输出对应的提示信息。*/ #include <stdio.h> #include<ctype.h> void main() { char ch; scanf("%c",&ch); if(ch>='A' && ch<='Z') { printf("upper\n"); } else if(ch>='a' && ch<='z') { printf("lower\n"); } // else if(ch>='1'&& ch<='9') 此处出错,换成库函数中的isdigit即可 else if(isdigit(ch)) { printf("digit\n"); } else { printf("other\n"); } }
/* 根据一个年份,判断是否是闰年。*/ #include <stdio.h> void main() { int year; scanf("%d",&year); if(year%4==0 && year%100!=0 || year%400==0) printf("Yes\n"); else printf("No\n"); }
总结
- ASCII码,简称asc码,是C语言的重要部分,通常用于加密。
- ASCII 码使用指定的7 位或8 位二进制数组合来表示128 或256 种可能的字符。标准ASCII 码也叫基础ASCII码,使用7 位[二进制数]来表示所有的大写和小写字母,数字0 到9、标点符号
- 大写变小写是加
- ctype.h库函数中 isupper() islower() isdigit()均可用于判断类型,超级好用
- 闰年 能被4整除,但不能被100整除,如2100不是
- 能被4整除又能被400整除
- 四年一闰,百年不闰,四百年再闰。
- 点赞
- 收藏
- 分享
- 文章举报