标签:com src 6.2 sharp 四舍五入 image double ima hello
Part1: 格式化输出函数printf()和格式化输入函数scanf()
%d:按十进制整数输出;%f:按浮点数输出;%c:按字符输出;%e:按指数形式输出;%s:按字符串输出;%5d:输出宽度为5的十进制整数;%lf:输出双精度(double)型的浮点数;%.3f:输出小数点后保留3位数(四舍五入)的浮点数
%6.2f:输出宽度为6,小数点后保留2位数的浮点数
问题回答:当在scanf里输入double型的浮点数时,输出必须使用%lf
#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; }
part4
#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; }
#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; }
part5
#include <stdio.h> int main() { char answer; printf("输入你的答案: "); scanf("%c",&answer); switch(answer) { case ‘A‘:printf("yes,you are right\n");break; default:printf("try again\n"); } return 0; }
标签:com src 6.2 sharp 四舍五入 image double ima hello
原文地址:https://www.cnblogs.com/konosuba/p/10633432.html