标签:char 初步 语句 default ble \n 等级 getch turn
Part 1:
#include <stdio.h> int main() { double x,y; char c1,c2,c3; int a1,a2,a3; scanf("%d%d%d",a1,a2,a3); printf("%d,%d,%d\n",a1,a2,a3); scanf("%c%c%c",&c1,&c2,&c3); printf("%c%c%c\n",c1,c2,c3); scanf("%f,%lf",&x,&y); printf("%f,%lf\n",x,y); return 0; }
#include <stdio.h> int main() { double x,y; char c1,c2,c3; int a1,a2,a3; scanf("%d%d%d",&a1,&a2,&a3); printf("%d,%d,%d\n",a1,a2,a3); scanf("%c%c%c",&c1,&c2,&c3); printf("%c%c%c\n",c1,c2,c3); scanf("%lf,%lf",&x,&y); printf("%lf,%lf\n",x,y); return 0; }
Part 2:
#include <stdio.h> int main() { char ch; ch = ‘A‘; putchar(ch); putchar(ch+32); putchar(‘\x41‘); putchar(‘\n‘); return 0; }
#include <stdio.h> int main() { char ch; ch = getchar(); putchar(ch); printf("%c",ch); return 0; }
Part 4:
#include <stdio.h> int main() { int level; printf("输入现在状态等级(1-5): "); scanf("%d",&level); switch(level) { case 1: printf("high翻了:)\n"); break; case 2: printf("low爆了:(\n"); break; default: printf("一言难尽,无法概括。。。\n"); } return 0; }
删除最后的break, 保存并重新编译后,再次运行
#include <stdio.h> int main() { int level; printf("输入现在状态等级(1-5): "); scanf("%d",&level); switch(level) { case 1: printf("high翻了:)\n"); case 2: printf("low爆了:(\n"); default: printf("一言难尽,无法概括。。。\n"); } return 0; }
发现程序会一直运行下去
Part 5:
#include <stdio.h> int main() { int x; printf("请输入你的答案(A,B,C or D):"); scanf("%c",&x); switch(x) { case ‘A‘ :printf("Binggo, you are right~") ;break; default: printf("try again~");break; } return 0; }
总结:这次初步了解和体会了if和switch语句,更加让我体会到C语言的奇妙,而且我知道了没有break会使程序一直运行下去,在以后的运用和学习中,必须注重这个点。
标签:char 初步 语句 default ble \n 等级 getch turn
原文地址:https://www.cnblogs.com/yesung/p/10631942.html