c prime plus 课后编程习题第三章答案

3-1 略

3-2

#include <stdio.h>
int main(void)
{
    printf("please enter a value.\n");
    int value;             //注意小写的a ASCll码值为97,大写A的ASCLl为65
    scanf("%d",&value);    //往后依次减一
    printf("%c\n",value);
    return 0;
}

3-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 thet!\n");
    return 0;
}

3-4

#include <stdio.h>
int main()
{
    float a;
    scanf("%f",&a);
    printf("%f\n",a);
    printf("%e\n",a);
    printf("%x\n",a);


    return 0 ;

}

3-5

#include <stdio.h>
int main(void)
{
    int age;
    scanf("%d",&age);
    double second = 3.156e7;      //一开始用的float,不行,范围不够
    printf("%g\n",age * second);
    return 0;
}

3-6

#include <stdio.h>
#define MASS_PER_MOLE 3.0e-23
#define MASS_PER_QUART 950

int main(void)
{
    double quart;

    printf("Please enter a quart for water: ");
    scanf("%lf", &quart);
    printf("%g quart water have %e water molecules.\n", quart, quart * MASS_PER_QUART / MASS_PER_MOLE);

    return 0;
}

3-7

#include <stdio.h>
#define CM_PER_INCH 2.54

int main(void)
{
    double inch;

    printf("Please enter your height(inch): ");
    scanf("%lf", &inch);
    printf("Your height is %g cm.\n", inch * CM_PER_INCH);

    return 0;
}

 3-8

#include <stdio.h>
#define PINT_PER_CUP 2
#define CUP_PER_OUNCE 8
#define OUNCE_PER_BIGSPOON 2
#define BIGSPOON_PER_TEASPOON 3

int main(void)
{
    double pint, ounce, cup;
    double bigspoon, teaspoon;

    printf("Please you enter a number of cups: ");
    scanf("%lf", &cup);
    pint = cup / PINT_PER_CUP;
    ounce = cup * CUP_PER_OUNCE;
    bigspoon = ounce * OUNCE_PER_BIGSPOON;
    teaspoon = bigspoon * BIGSPOON_PER_TEASPOON;

    printf("Here are some ways to show %g cups:\n", cup);
    printf("Pint: %g\n", pint);
    printf("Ounce: %g\n", ounce);
    printf("Bigspoon: %g\n", bigspoon);
    printf("Teaspoon: %g\n", teaspoon);

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值