《C Primer Plus》第三章编程题

来源:互联网 发布:python 股票交易平台 编辑:程序博客网 时间:2024/05/22 11:45

1、编写一个程序,要求输入一个ASCII码值,然后输出相应的字符.

#include <stdio.h>int main(void){int s;printf("Please enter an ASCII(0-255):\n");scanf("%d",&s);printf("The character is %c.\n",s);getchar();return 0;}

2、编写一个程序,发出警报声。

#include <stdio.h>int main(void){printf("\aWarnning");getchar();return 0;}

3、编写一个程序,读入一个浮点数,并分别以小数形式和指数形式打印。

#include <stdio.h>int main(void){float s;printf("Please enter a float;\n");scanf("%f",&s);printf("The input is %f or %e.\n",s,s);getchar();return 0;}

4、一年约有3.156x10^7s。编写一个程序,要求输入您的年龄,然后显示该年龄合多少秒。

#include <stdio.h>int main(void){int SECOND=3.156e7;int age;printf("Please enter your age:\n");scanf("%d",&age);printf("You have been lived %d seconds.\n",age*SECOND);getchar();return 0;}


5、一个水分子的质量约为3.0x10^-23g,一夸脱水约有950g。编写一个程序,要求输入水的夸脱数,然后显示这么多水中包含多少个书分子。

#include <stdio.h>int main(void){int G_QUALITY = 950;int WATER_QUALITY =3e-23;long double quality;printf("Please enter a float:\n");scanf("%lf",&quality);printf("You entered %lfg water:\n",quality);printf("It contains %lld water-numerators.\n",(quality*G_QUALITY)/WATER_QUALITY);getchar();return 0;}