C primer Plus第六版 第三章编程练习

2.编写一个程序,要求提示输入一个ASCII码值,然后打印输入的字符

#include<stdio.h>
//数据在内存中的存储形式是一样的
//%c显示ASCII,%d显示十进制数字
int main(void)
{
	char number;
	printf("Please input a number:\n");
	scanf("%d", &number);
	printf("ASCII:%c", number);

	return 0;
}

3.编写一个程序,发出一声警报,然后打印下面的文本:

Started by the suddden sound, Sally shouted,

"By the Great Pumpkin,what was that!"

#include<stdio.h>
//  \a	蜂鸣声  \" 输出"
int main(void)
{
	printf("\aStarted by the suddden sound, Sally shouted,\n");
	printf("\"By the Great Pumpkin, what was that!\"");
	return 0;
}

4.编写一个程序,读取一个浮点数,先打印成小数形式,在打印成指数形式。然后,如果系统支持,再打印成p计数法(即16进制计数法)。按以下格式输出:

Enter a float-point value: number

fixed-point notation: 64.250000

exponetial notation: 60425000e+01

p notation: 0x1.01p+6

#include<stdio.h>
//%f 浮点数显示 %e科学计数法显示  %a十六进制科学计数法显示
int main(void)
{
	float number;
	printf("Enter a float-point value: ");
	scanf("%f", &number);
	printf("\nfixed-point notation: %f", number);
	printf("\nexponetial notation: %e", number);
	printf("\np notation: %a", number);
	return 0;
}

5.一年大约有3.156*10^7秒。编写一个程序,提示用户年龄,然后显示该年龄对应的秒数。

#include<stdio.h>

int main(void)
{
	float age;
	float second = 3.156e+7;
	printf("Please input your age: ");
	scanf("%f", &age);
	printf("age_seconds: %f", age * second);
	return 0;
}

6.一个水分子的质量约为3.0*10^-23克。1夸脱水大约是950克。编写一个程序,提示用户输入水的夸脱数,并显示水分子的质量。

#include<stdio.h>

int main(void)
{
	float water;
	float one_molecule = 3.0e-23;
	int one_kuatuo = 950;
	printf("Please input water : ");
	scanf("%f", &water);
	printf("water_molecule: %e", one_molecule * one_kuatuo* water);
	return 0;
}

7.一英寸相当于2.54厘米,编写程序提示用户输入身高(英寸),然后以厘米为单位显示身高。

#include<stdio.h>

int main(void)
{
	float units=2.54;
	float yingcun; 
	printf("Please input your height : ");
	scanf("%f", &yingcun);
	printf("your heiht: %f", units * yingcun);
	return 0;
}

8.在美国的体积测量系统中,1品脱=2杯,1杯=8盎司,1盎司=2大汤勺,1大汤勺=3茶勺。

编写一个程序,提示用户输入的杯数,并以品脱,盎司,汤勺,茶勺为单位显示容量。

#include<stdio.h>
//1品脱=2杯,1杯=8盎司,1盎司=2大汤勺,1大汤勺=3茶勺
int main(void)
{
	float cup;
	printf("Please input your cpus : ");
	scanf("%f", &cup);
	printf("The pingtuo: %f\n",cup/2 );
	printf("The angsi: %f\n",cup*8 );
	printf("The tangshao: %f\n",cup*16 );
	printf("The chashao: %f\n",cup*48 );
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值