欢迎光临散文网 会员登陆 & 注册

C Primer Plus Test3

2019-12-25 20:12 作者:啷个里格朗郎郎  | 我要投稿

练习题来源:C Primer Plus (第6版)中文版

这章主要为数据的练习,基本数据类型都有涉及。

此为本人所写,非最优化。具体参考异步社区。

3.1

/*

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

*/

#include<stdio.h>

#include<stdlib.h>

int main(){


char ch;

printf("please input an ASCII:\n");

scanf("%d", &ch);

printf("%c\n",ch);

system("pause");

return 0;

}

3.2

/*

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

Startled by the sudden sond, Sally shouted,

"By the Great Pumkin, what was that!" 

*/

#include<stdio.h>

#include<stdlib.h>

int main(){

printf("\a");

printf("Startled by the sudden sond, Sally shouted,\n");

printf("\"By the Great Pumkin, what was that!\"\n");

system("pause");

return 0;

}

3.3

/*

读取一个浮点数,先打印成小数点形式,再打印出指数形式,

最后打印成p计数法(十六进制)。

Enter a floating-point values:64.25

fixed-point notation:64.250000

exponential notation:6.425000e+01

p notation: 0x1.01p+6 

*/

#include<stdio.h>

#include<stdlib.h>

int main(){


float f;

printf("Enter a floating-point values:");

scanf("%f",&f);

printf("fixed-point notation:%.6f\n",f);

printf("exponential notation:%e\n",f);

printf("p notation:%a\n",f);

system("pause");

return 0;

3.4

/*

一年大约有3.156x10的7次秒,编写一个程序,提示用户输入年龄,

显示年龄该对应的秒数 

**/

#include<stdio.h>

#include<stdlib.h>

int main(){


double min = 3.156e7;

double m ;

int age;

printf("Enter your age:");

scanf("%d", &age);

m = age * min;

printf("the age is the same as %e", m);

system("pause");

return 0;

}

3.5

/*

一个水分子的质量约为3.0x10的-23次克,一夸脱水大约是950克。

编写一个程序,提示用户输入的水的夸脱数,并显示水分子的数量。 

*/

#include<stdio.h>

#include<stdlib.h>

int main(){


double w = 3e-23;

double kua = 950.0;

double num,number;

printf("Enter the kuatuo:");

scanf("%lf",&num);

number =(num *kua) / w;


printf("The water\'s fenzi number is %e",number);

system("pause");

return 0;

3.6

/*

1英寸相当于2.54厘米。编写一个程序,提示用户输入身高(英寸),

然后以厘米显示身高。 

*/

#include<stdio.h>

#include<stdlib.h>

int main(){


float eq = 2.54;

float  tall, tall_limi;

printf("Enter your tall with yingcun:");

scanf("%f", &tall);

tall_limi = tall * eq;

printf("your tall is %f limi\n",tall_limi);

system("pause");

return 0;

3.7

/*

在美国的体积测量系统中,1品脱等于2杯,一杯等于8盎司,

1盎司等于2大汤勺,1大汤勺等于3茶勺。

提示用户输入杯数,并以品脱、盎司。汤勺。茶勺为单位进行输出。 

*/

#include<stdio.h>

#include<stdlib.h>

int main(){


float angsi,tangshao,chashao,pintuo;

int cup;

printf("Enter cup number:");

scanf("%d", &cup);

pintuo = cup / 2;

angsi = cup * 8;

tangshao = angsi * 2;

chashao = tangshao * 3; 

printf("pintuo : %.1f\n", pintuo);

printf("angsi : %.1f\n", angsi);

printf("tangshao : %.1f\n", tangshao);

printf("chashao : %.1f\n", chashao);

system("pause");

return 0;

}


C Primer Plus Test3的评论 (共 条)

分享到微博请遵守国家法律