1、經過試驗(即編寫帶有此類問題的程序)觀察系統如何處理整數上 溢、浮點數上溢和浮點數下溢的狀況。code
#include<stdio.h> int main(void) { unsigned int a=4294967295; float b=3.4E38; float c=b*10; float d=0.1234E-2; printf("%u+1=%u\n",a,a+1); printf("%e*10=%e\n",b,c); printf("%f/10=%f\n",d,d/10); return 0 }
2、編寫一個程序,發出一聲警報,而後打印下面的文本:get
Startled by the sudden sound, Sally shouted, "By the Great Pumpkin, what was that!"
#include<stdio.h> int main() { printf("\aStartled by the sudden sound, Sally shouted,\n"); printf("\"By the Great Pumpkin, what was that!\"\n"); return 0; }
3、編寫一個程序,讀取一個浮點數,先打印成小數點形式,再打印成指 數形式。而後,若是系統支持,再打印成p記數法(即十六進制記數法)。 按如下格式輸出(實際顯示的指數位數因系統而異):input
Enter a floating-point value: 64.25 fixed-point notation: 64.250000 exponential notation: 6.425000e+01 p notation: 0x1.01p+6
#include<stdio.h> int main(void) { float a; printf("Enter a floating-point value:"); scanf("%f",&a); getchar(); printf("fixed-point notation:%f\n",a); printf("exponential notation:%e\n",a); printf("p notation:%a\n",a); return 0; }
4、一年大約有3.156×107秒。編寫一個程序,提示用戶輸入年齡,而後顯 示該年齡對應的秒數。io
#include<stdio.h> int main(void) { #include <stdio.h> #include <stdlib.h> int main() { const float t = 3.156e7; int age; printf("%e\n", age * t); return 0 }
5、1個水分子的質量約爲3.0×10−23克。1夸脫水大約是950克。編寫一個 程序,提示用戶輸入水的夸脫數,並顯示水分子的數量。float
#include <stdio.h> #include <stdlib.h> int main() { const float t = 3e-23; int n; printf("Input n:"); scanf("%d", &n); printf("%e\n", n * 950 / t); } return 0
6、1英寸至關於2.54釐米。編寫一個程序,提示用戶輸入身高(/英 寸),而後以釐米爲單位顯示身高。程序
#include <stdio.h> #include <stdlib.h> int main() { const float t = 2.54; float n; printf("Input n:"); scanf("%f", &n); printf("%f\n", n / t); } return 0
7、在美國的體積測量系統中,1品脫等於2杯,1杯等於8盎司,1盎司等 於2大湯匙,1大湯匙等於3茶勺。編寫一個程序,提示用戶輸入杯數,並以 品脫、盎司、湯匙、茶勺爲單位顯示等價容量。思考對於該程序,爲什麼使用 浮點類型比整數類型更合適?di
#include <stdio.h> int main() { const float pt = 0.5; const float gs = 8.0; const float ts = gs * 2; const float cs = ts * 3; printf("Input n:"); float n; scanf("%f", &n); printf("pt:%f\n", pt * n); printf("gs:%f\n", gs * n); printf("ts:%f\n", ts * n); printf("cs:%f\n", cs * n); return 0 }
8、編寫一個程序,要求提示輸入一個ASCII碼值(如,66),而後打印 輸入的字符。思考
#include<stdio.h> int main(void) { int a; printf("please enter a ASCII ma:"); scanf("%d",&a); printf("the input ASCII ma is %c:",a); getchar(); getchar(); return 0; }