文章目录
1. 第1题
1.1 题目描述
不做
1.2 编程源码
1.3 结果显示
2. 第2题
2.1 题目描述
编写一个程序,要求提示输入一个ASCII码值(如,66),然后打印输入的字符。
2.2 编程源码
# include<stdio.h>
int main(){
int c;
printf("请输入字符的ASCII码:\n");
scanf("%d", &c);
printf("%c\n",c);
return 0;
}
2.3 结果显示

3. 第3题
3.1 题目描述
编写一个程序,发出一声警报,然后打印下面的文本:
Startled by the sudden sound, Sally shouted,
"By the Great Pumpkin, what was that! "
3.2 编程源码
# include<stdio.h>
int main(){
printf("\aStartled by the sudden sound, Sally shouted,\n\"By the Great Pumpkin, what was that! \"\n");
return 0;
}
3.3 结果显示

4. 第4题
4.1 题目描述
编写一个程序,读取一个浮点数,先打印小数点形式,再打印成指数形式。然后,如果系统支持,再打印成p计数法(即十六进制记数法)。按以下格式输出(实际显示的指数位数因系统而异):
Enter a floating-point value: 64.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+01
p notation: 0x1.01p+6
4.2 编程源码
# include<stdio.h>
int main(){
float f;
printf("Enter a floating-point value:");
scanf("%f", &f);
printf("fixed-point notation: %f\n", f);
printf("exponential notation: %e\n", f);
printf("p notation: %a\n", f);
return 0;
}
4.3 结果显示

5. 第5题
5.1 题目描述
一年大约有3.156 *10^7秒。编写一个程序,提示用户输入年龄,然后显示年龄对应的秒数。
5.2 编程源码
# include<stdio.h>
int main(){
int n;
printf("Enter a your year old:");
scanf("%d", &n);
printf("%d years = %f seconds\n", n, n*365*24*3600*3.156e7);
return 0;
}
5.3 结果显示

6. 第6题
6.1 题目描述
1个水分子的质量约为3.0*10^-23克。一夸脱水大约是950克。编写一个程序,提示用户输入水的夸脱数,并显示水分子的数量。
6.2 编程源码
# include<stdio.h>
int main(){
float n;
printf("Enter the kua of water:");
scanf("%f", &n);
printf("%f kua = %f seconds\n", n, n*950/3e-23);
return 0;
}
6.3 结果显示

7. 第7题
7.1 题目描述
1英寸相当于2.54厘米。编写一个程序,提示用户输入身高(英寸),然后以厘米为单位显示身高。
7.2 编程源码
# include<stdio.h>
int main(){
float n;
printf("Enter your height in inch: ");
scanf("%f", &n);
printf("%f in = %f cm\n", n, n*2.54);
return 0;
}
7.3 结果显示

8. 第8题
8.1 题目描述
在美国的体积测量系统中,1品脱等于2杯,1杯等于8盎司,1盎司等于2大汤勺,1大唐莎等于3茶勺。编写一个程序,提示用户输入杯数,并以品脱、盎司、汤勺、茶勺为单位显示等价容量。思考对于该程序,为何使用浮点数类型比正式合适。
8.2 编程源码
# include<stdio.h>
int main(){
float n;
printf("Enter your cups: ");
scanf("%f", &n);
printf("%f cups = %f pin = %f ounce = %f big spoon = %f tea spoon \n", n, n/2, n*8,n*8*2,n*8*2*3);
return 0;
}
8.3 结果显示

文章介绍了八道编程练习题目,涉及ASCII码字符输入、字符打印、警报、浮点数表示、年龄和时间换算、水分子量计算、英寸厘米转换以及美国体积测量系统的换算,展示了基本的编程技巧和数据类型使用。

1260

被折叠的 条评论
为什么被折叠?



