Unit Three-Program test
生活随笔
收集整理的這篇文章主要介紹了
Unit Three-Program test
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
編程練習——《C Primer Plus》
Unit Three-Program test
Program_test_5
/* Program Test :一年大約有 3.156×10^7秒。編寫一個程序,提示用戶輸入年齡,然后顯示該年齡對應的秒數。 */ #include<stdio.h> int main(void) {int i_age;double d_seconds;double d_year = 3.156E7;printf("Please input your age:\n");scanf("%d",&i_age);d_seconds = i_age * d_year;printf("The years transfer into seconds of your age is %.2f", d_seconds);return 0; }Program_test_7
/*Program Test 7 1英寸相當于 2.54 厘米。 編寫一個程序,提示用戶輸入年齡 然后顯示該年齡對應的描述。 */ #include<stdio.h> int main(void) {double d_inchs, d_height;printf("Please input your height(by inchs):\n");scanf("%lf",&d_inchs); //double型 scanf()函數要用 %lf d_height = d_inchs*2.54;printf("Your height is: %.2f by centimeters.\n",d_height); // printf() 函數中 float 和 double 都可以用 %f return 0;}Program_test_8
/*Program Test 8 在美國的體積測量系統中; 1品脫等于2杯;1杯等于8蠱司;1蠱司等于2大湯勺;1大湯勺等于3茶勺; 編寫一個程序,提示用戶輸入杯數; 并以品脫、蠱司、湯勺、茶勺為單位顯示等價容量。 */ #include <stdio.h> int main(void) {float pints, cups, ounces, tablespoons, teaspoons ;printf("Please input some cups:");scanf("%f", &cups);pints = cups/2;ounces = cups*8;tablespoons = ounces*2;teaspoons = tablespoons*3;printf("%.2f,%.2f,%.2f,%.2f",pints,ounces,tablespoons,teaspoons);return 0; }總結
以上是生活随笔為你收集整理的Unit Three-Program test的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第3章 数据和C
- 下一篇: 第4章 字符串和格式化输入/输出