書本4-1

1:加載速度 #include<stdio.h> #include<stdlib.h> int main() { float x, y, z; printf("請輸入你的下載速度(mb/s):"); scanf("%f", &x); printf("請輸入你的下載(mb):"); scanf("%f", &y); z = y / x; printf("At %f megabits per second, a file of %f megabytes downloads in %f seconds", x, y, z); system("pause"); return 0; } 2:名字與寬度 #include<stdio.h> #include<stdlib.h> int main() { char name[20]; printf("請輸入你的名字:"); scanf("%s", name); printf("「%s」\n", name); printf("「%20s」\n",name); printf("「%-20s」\n",name); printf("「 %s 」",name); system("pause"); return 0; } 3:身高和姓名 #include<stdio.h> #include<stdlib.h> int main() { char name[20]; float tall; printf("請輸入你的名字:"); scanf("%s", name); printf("請輸入你的身高:"); scanf("%f", &tall); printf("%s,你的身高爲%f釐米", name, tall); system("pause"); return 0; } 4:輸出浮點數 #include<stdio.h> #include<stdlib.h> int main() { float x; printf("請輸入浮點數:"); scanf("%f", &x); printf("The input is %.1f or %e\n", x); printf("The input is %+.3f or %E\n", x); system("pause"); return 0; } 5:名姓 #include<stdio.h> #include<stdlib.h> int main() { char name1[20],name2[20]; printf("請輸入你的名:"); scanf("%s",name1); printf("請輸入你的姓:"); scanf("%s",name2); printf("你的名姓是:%s%s\n",name1,name2); system("pause"); return 0; }input

相關文章
相關標籤/搜索