您的位置:首页 > 其它

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

2013-01-18 17:20 351 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: