标签:mamicode 编程练习 bing evel turn char cas eve 字符
part 1
(1)
#include <stdio.h> int main() { int x=1234; float f=123.456; double m=123.456; char ch=‘a‘; char a[]="Hello, world!"; // 定义一个数组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, %0.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; }
(2)修改后
#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("%f,%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; }
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 0; }
part 5 简单编程练习
#include <stdio.h> int main(){ char answer; printf("请输入你的答案(A,B,C or D):"); scanf("%c",&answer); if(answer==‘A‘) printf("Binggo,you are right~\n"); else printf("try again~\n"); return 0; }
实验总结:要注意输入时输入法的中英文和大小写的状态
要多加练习,熟练使用各字符
标签:mamicode 编程练习 bing evel turn char cas eve 字符
原文地址:https://www.cnblogs.com/zhc0916/p/10629412.html