C primer plus第3章(数据和C)习题

1.合适的数据类型

a.人口 int、short、unsigned、unsigned short 

b.DVD影碟的价格 float

c.字母  char

d.字母出现的次数 int 或者unsigned

 2.长度超过int所能表示的范围要用long

3. 获得一个32位的有符号整数类型,可以使用那些可移植数据类型?每种选择的理由是什么?

4. 

a. '\b' char  光标退一格

b. 1066 int

c. 99.44 float

d. 0xAA unsigned int 十六进制

e. 2.0e30 double

5.

#include <stdio.h>

main(void)

{

float g;

float tax,rate;

g = 2e1;

tax = rate * g

}

6.

%d 12

%#x 0x3

%c 'C'

%e 2.34E07

%c '\040'

%f 7.0

%ld 6l

%f 6.0


7.

%ud 012

%Le 2.9e05L

%c 's'

%ld 100000

%c 'n'

%f 20.0f

%x 0x44


8.

int imate = 2;

long short = 53456;

char grade = 'A';

float log = 2.71828;

printf("The odds against the %d where %d to 1.\n", imate, shot);

printf("A score of %f is not an %c grade.\n", log,grade);


9.回车

ch = '\r';//转义序列

ch = 13;//十进制

ch = '\015';//八进制

ch = '\xd' = ‘\0x0d’;//十六进制


10.

#include <stdio.h>

int main(void)

{

int crows, legs;

printf("How many cow legs did you count?\n");

scanf("%d", legs);

cows = legs / 4;

printf("That implies there are %d cows.\n", cows);

}

11.

\n 换行

\\ 反斜杠

\" 双引号

\t 水平制表符



编程

2.输入ascii值,输出相应字符

#include <stdio.h>
int main(void)
{
    int ascii;
    scanf("%d", &ascii);
    printf("%c",ascii);
    return 0;
}

3、发出警报,打印字符

#include <stdio.h>
int main(void)
{
    printf("\aBy the Great Pumpkin,what was that");
    return 0;
}

4、输入浮点数,以小数和指数形式显示

#include <stdio.h>
int main(void)
{
    float f;
    scanf("%f", &f);
    printf("%f or %e", f, f);
    return 0;
}

5.输入年龄,计算秒

#include <stdio.h>
int main(void)
{
    float second = 3.156E7;
    int years;
    scanf("%d", &years);
    printf("%e", years * second);
    return 0;
}

6.输入夸脱显示水分子

#include <stdio.h>
int main(void)
{
    float quart;
    //1夸脱 = 950g
    float g = 950.00;
    //1个水分子的质量 g
    float hydrone = 3.0E-23;
    scanf("%f", &quart);
    printf("%e", quart * hydrone * g);
    return 0;
}

7.

#include <stdio.h>
#include <string.h>
int main(void)
{

    //1英寸= 2.54 cm
    float conver;
    float inputNum;
    char * iunit;
    char * ounit;
    int type;

    printf("输入1(inch->cm)\n输入2(cm->inch)\n");
    scanf("%d", &type);

    if(type == 1)
    {
        conver = 2.54;
        iunit = "inch";
        ounit = "cm";
    }
    else if(type == 2)
    {
        conver = 1/2.54;
        iunit = "cm";
        ounit = "inch";
    }
    printf("请输入%s\n", iunit);
    scanf("%f", &inputNum);
    printf("%e%s\n", inputNum * conver, ounit);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值