标签:相同 http def ble 蓝屏 背景 ice img exit
part1
ex2-1
#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);//输出宽度为8和2 printf("%f, %8f, %8.1f, %0.2f, %.2e\n",f,f,f,f,f);//输出宽度为8,输出的总长度最大值为8且保留一位小数,保留2位小数,以指数形式输出且保留2位小数 printf("%lf\n",m); printf("%3c\n", ch);//输出的占位3个字符 printf("%s\n%15s\n%10.5s\n%2.5s\n%.3s\n",a,a,a,a,a);//输出15个字符的字符串 return 0; }
ex2-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("%lf,%lf\n",x,y); return 0; }
double型要用长整型,scanf中要加上地址符
part2
ex2-3
#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) printf("构成等边三角形\n"); else if(a==b || a==c || b==c) printf("构成等腰三角形\n"); else printf("构成一般三角形\n"); } else printf("不能构成三角形\n"); return 0; }
当替换代码后也成立
ex2-4
#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请输入, 选择你想使用的屏幕配色方案: "); choice=getchar(); 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 try@_@\n"); return 0; }
part3
1.
#include<stdio.h> int main(){ int x,y,z; printf("输入一个三位整数:"); scanf("%d",&x); z=x; y=x/100; x=x%100; y=(x/10)*10+y; x%=10; y=y+x*100; if(y==z) printf("该整数正序与逆序相同"); else printf("该整数正序与逆序不相同"); return 0; }
2.
#include<stdio.h> #include<stdlib.h> int main() { int year,month,day,leapyear;
printf("输入年份 月份\n"); scanf("%d%d",&year,&month); if(year<0 || month<1 || month>12) { printf("输入的数据错误!\n"); exit(0); } leapyear=year%4==0&&year%100!=0 || year%400==0; if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) day=31; else if(month==4 || month==6 || month==9 || month==11) day=30; else day=28+leapyear; printf("%d年%d月的天数为:%d\n",year,month,day); return 0; }
3.
#include<stdio.h> #include<stdlib.h> int main() { int score;
printf("输入分数0~100\n"); scanf("%d",&score); if(score<0||score>100) { printf("输入数据错误\n"); } else switch(score/10) { case 10: case 9:printf("优秀\n");break; case 8:printf("良好\n");break; case 7:printf("中等\n");break; case 6:printf("及格\n");break; default:printf("不及格\n");break; } return 0; }
标签:相同 http def ble 蓝屏 背景 ice img exit
原文地址:https://www.cnblogs.com/wudiqi/p/11802553.html