实验二
PART1 格式化输出函数printf()和格式化输出函数scanf()
#include <stdio.h> int main() { int x=1234; float f=123.456; double m=123.456; char ch='a'; char a[]="Hello,world"; int y=3,z=4; printf("%d %d\n",y,z); printf("y=%d,z=%d\n",y,z); printf("%8d,%2d\n",x,x); printf("%f,%8f,%8.1f,%.2f,%.2e\n",f,f,f,f,f); printf("%lf\n",m); printf("%3c\n",ch); printf("%s\n%15s\n%10.5s\n%2.5s\n%.3s\n",a,a,a,a,a); 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; }
PART4 switch语句体验练习
#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
无break
有break
PART5
#include<stdio.h> int main() { char ch; printf("请输入你的答案A,B,C,orD\n"); scanf("%c",&ch); if(ch=='A') printf("binggo,you are right"); else printf("try again~"); return 0; }
实验总结与体会:大致熟练了循环语句用法,实验内容虽然有点多,但是收获不少。
https://www.cnblogs.com/MR-XN/p/10619676.html
https://www.cnblogs.com/plutocharon/p/10623854.html
https://www.cnblogs.com/ssyxs/p/10601509.html