《C Primer Plus》(第6版)编程练习——第3章

第2题

#include <stdio.h>
int main(void)
{
	int ascii;
	
	printf("Enter an ASCII code: ");
	scanf("%d", &ascii);
	printf("%d is the ASCII code for %c.\n", ascii, ascii);

	return 0;
}

第3题

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

	return 0;
}

第4题

#include <stdio.h>
int main(void)
{
	float num;

	printf("Enter a floating-point value: ");
	scanf("%f", &num);
	printf("fixed-point notation: %f\n", num);
	printf("exponential notation: %e\n", num);
	printf("p notation: %a\n", num);

	return 0;
}

第5题

#include <stdio.h>
int main(void)
{
	int age;
	double sec;
	
	printf("Enter your age: ");
	scanf("%d", &age);
	sec = age * 3.156e7;
	printf("%e seconds for %d years.\n", sec, age);

	return 0;
}

第6题

#include <stdio.h>
int main(void)
{
	float mass_mol = 3.0e-23;
	float mass_qt = 950;
	float quarts;
	float molecules;

	printf("Enter the number of quarts of water: ");
	scanf("%f", &quarts);
	molecules = quarts * mass_qt / mass_mol;
	printf("%f quarts of water contain %e molecules.\n", quarts, molecules);

	return 0;
}

第7题

#include <stdio.h>
int main(void)
{
	float inch_cen = 2.54;
	float height_inch, height_cen;

	printf("Enter your height (inch): ");
	scanf("%f", &height_inch);
	height_cen = height_inch * inch_cen;
	printf("Your height is %.2f centimeters.\n", height_cen);

	return 0;
}

第8题

#include <stdio.h>
int main(void)
{
	float pint_cup = 2;
	float cup_ounce = 8;
	float ounce_soupspoon = 2;
	float soupspoon_teaspoon = 3;
	float pints, cups, ounces, soupspoons, teaspoons;

	printf("Enter the number of cups: ");
	scanf("%f", &cups);
	pints = cups / pint_cup;
	ounces = cups * cup_ounce;
	soupspoons = ounces * ounce_soupspoon;
	teaspoons = soupspoons * soupspoon_teaspoon;
	printf("%g cups is equivalent to: %5g pints\n", cups, pints);
	printf("                       or %5g ounces\n", ounces);
	printf("                       or %5g soupspoons\n", soupspoons);
	printf("                       or %5g teaspoons\n", teaspoons);

	return 0;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值