part1
第三行 8d,x 有四位, 预宽四格, 2 小于 4,2d 按原样输出
第三行 f 先转换成二进制, 小数位乘 2 得不到 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("%lf,%lf",&x,&y);
- printf("%lf,%lf\n",x,y);
- return 0;
- }
- part2
- #include <stdio.h>
- int main() {
- double a,b,c;
- scanf("%lf %lf %lf", &a, &b, &c);
- if(a<0 || b<0 || c<0)
- printf("不能构成三角形 \ n");
- else if(a+b>c && a+c>b && b+c>a) {
- if(a==b || a==c || b==c) {
- if (a==b && a==c)
- printf("构成等边三角形 \ n");
- else
- printf("构成等腰三角形 \ n");
- }
- else
- printf("构成一般三角形 \ n");
- }
- else
- printf("不能构成三角形 \ n");
- return 0;
- }
- ,
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int choice;
- // 显示菜单
- printf("输入 0~9 以内的数字, 选择屏幕背景色前景色方案: \n");
- printf("1-\t 黑底绿色 \ n");
- printf("2-\t 白底黑色 \ n");
- printf("3-\t 蓝底白色 \ n");
- printf("其它 -\t 黑底白色 (默认)\n");
- printf("\n 请输入, 选择你想使用的屏幕配色方案:");
- // 要求用户从键盘输入 0~9 的数字, 选择屏幕配色方案
- scanf("%d",&choice);
- // 根据用户输入, 设置屏幕配色方案
- if (choice == 1) {
- system("color 02");
- printf("《黑客帝国》一类的影视剧常见这种屏幕色:)\n");
- }
- else if(choice == 2) {
- system("color f0");
- printf("大部分编辑器默认是这种配色:)\n");
- }
- else if(choice == 3) {
- system("color 1f");
- printf("这是机器蓝屏故障时的不讨喜色:)\n");
- }
- else {
- system("color 0f");
- printf("控制台程序默认小黑窗:)\n");
- }
- printf("programming is fun, just [email protected][email protected]\n");
- return 0;
- }
- part3
- #include <stdio.h>
- int main(){
- int a,b,c=0;
- printf("putin:\n");
- scanf("%d",&a);
- b=a;
- while(b>0)
- {
- c=c*10+b%10;
- b=b/10;
- }
- if(a==c)
- printf("same\n");
- else
- printf("different\n");
- return 0;
- }
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- {
- int year,month,day,leapyear;
- printf("putin year\n");
- scanf("%d",&year);
- printf("putin month\n");
- scanf("%d",&month);
- if(year<0||month<1||month>12)
- {
- printf("error");
- exit(0);
- }
- else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
- printf("day=31");
- else if(month==2)
- {
- day=28+leapyear;
- printf("%d",day);}
- else
- printf("day=30");
- return 0;
- }
- #include<stdio.h>
- #include<stdlib.h>
- int main(){
- int score;
- scanf("%d",&score);
- if(score<0||score>100)
- {printf("not in range");
- exit(0);
- }
- switch(score/10)
- { case 10:
- case 9:printf("excellent");break;
- case 8:printf("good");break;
- case 7:printf("medium");break;
- case 6:printf("passed");break;
- default:printf("failed");break;
- }
- return 0;
- }
- part4
- #include<conio.h>
- #include<stdio.h>
- int main (){
- printf("press any key to begin");
- getch();
- //a game
- return 0;
- }
总结
if 中区分 = 和 ==
问题
为什么 123.456 float 输出是 0000001 而 dounle 是 00000000, 不是都要转换成二进制再转换十进制吗
实验 2
来源: http://www.bubuko.com/infodetail-3274623.html