2.编写一个程序,发出一声警报,然后打印下面的文本:
Startled by the sudden sound,Sally shouted,"By the Great Pumpkin,what was that!"
#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.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+01
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;
}