新建做業20191011121223

2.編寫一個程序,發出一聲警報,而後打印下面的文本:

Startled by the sudden sound,Sally shouted,"By the Great Pumpkin,what was that!"code

#include<stdio.h>
int main()
{
	printf("\a");
	printf("Startled by the sudden sound,\n");
	printf("Sally shouted,\n");
	printf("\"By the Great Pumokin,what was that!\"");
	return 0;
}

3.編寫一個程序,讀取一個浮點數,先打印成小數點形式,再打印成指 數形式。而後,若是系統支持,再打印成p記數法(即十六進制記數法)。 按如下格式輸出(實際顯示的指數位數因系統而異):

Enter a floating-point value: 64.25input

fixed-point notation: 64.250000io

exponential notation: 6.425000e+01float

p notation: 0x1.01p+6程序

#include<stdio.h>
int main()
{
	float fds=64.25;
	printf("Enter a floating-point value:%.2f\n",fds);
	printf("fixed-point notation:%f6\n",fds);
	printf("exponential notation:%e\n",fds);
	printf("p notation:%a",fds);
	return 0;
}

4.一年大約有3.156×107秒。編寫一個程序,提示用戶輸入年齡,而後顯 示該年齡對應的秒數。

#include<stdio.h>
int main()
{
	long totalSecond;
	int age;
	printf("please input your age\n");
	scanf("%d",&age);
	totalSecond=age*3.156e7;
	printf("you have lived %d second\n",totalSecond);
	return 0;
}

5.1個水分子的質量約爲3.0×10−23克。1夸脫水大約是950克。編寫一個 程序,提示用戶輸入水的夸脫數,並顯示水分子的數量。

#include<stdio.h>
#define MASS_H2O 3.0e-23
#define MASS_QT 950
int main()
{
	float quarts,countH2O;
	printf("please input the number of quarts of water\n");
	scanf("%f",&quarts);
	countH2O=quarts*MASS_QT/MASS_H2O;
	printf("%f quarts of water contain %e count of H2O",quarts,countH2O);
	return 0;
}

6.1英寸至關於2.54釐米。編寫一個程序,提示用戶輸入身高(/英 寸),而後以釐米爲單位顯示身高。

#include<stdio.h>
#define MASS_yc 2.54
int main()
{
	int yc;
	float longth;
	printf("please input the number of yc\n");
	scanf("%d",&yc);
	longth=yc*MASS_yc;
	printf("your longth is %f cm",longth);
	return 0;
}

7.在美國的體積測量系統中,1品脫等於2杯,1杯等於8盎司,1盎司等 於2大湯匙,1大湯匙等於3茶勺。編寫一個程序,提示用戶輸入杯數,並以 品脫、盎司、湯匙、茶勺爲單位顯示等價容量。思考對於該程序,爲什麼使用 浮點類型比整數類型更合適?

#include<stdio.h>
int main()
{
	float a,b,c,d,e;
	printf("please input the number of bulk\n");
	scanf("%f",&a);
	b=2*a;
	c=8*a;
	d=16*a;
	e=3*d;
	printf("品脫=%f,\n盎司=%f,\n湯匙=%f,\n茶勺=%f,\n",b,c,d,e);
	return 0;
}

8.編寫一個程序,要求提示輸入一個1 編寫一個程序,要求提示輸入一個ASCII碼值(如,66),而後打印 輸入的字符。(如,66),而後打印 輸入的字符。

#include<stdio.h>
int main()
{
	int c;
	printf("輸入一個ASCII碼值(如:66)\n");
	scanf("%d",&c);
	printf("字符爲%c\n",c); 
	return 0;
}
相關文章
相關標籤/搜索