/*习题1:查看当前系统整数的上限和下限*/#include<stdio.h>#include<limits.h>//INT_MAX,INT_MIN#include<float.h>intmain(void){int i =2147483647;float a =3.402823e38*100.0f;float b =-1.175494e-38/100.0f;printf("%d,%d,%d\n",i,i+1,i+2);// printf("%d,%d\n",INT_MAX,INT_MIN);// printf("%e,%e\n",FLT_MAX,FLT_MIN);printf("%e\n",a);printf("%e\n",b);return0;}
2147483647,-2147483648,-21474836471.#INF00e+000-1.175493e-040--------------------------------
Process exited after 0.03005 seconds with return value 0
请按任意键继续...
/*习题2:编写一个程序,要求输入一个ASCII码值,然后输出相应的字符*/#include<stdio.h>intmain(void){int ascii;printf("Please enter an ASCII code:\n");scanf("%d",&ascii);printf("%d is the ASCII code for %c.\n",ascii,ascii);return0;}
Please enter an ASCII code:
6565 is the ASCII code for A.--------------------------------
Process exited after 1.949 seconds with return value 0
请按任意键继续...
/*习题3:编写一个程序,发出警报声,并打印下列文字“Stareled by the sudden sound, sally shouted, “By the Great Pukin,what was that!” ”*/#include<stdio.h>intmain(void){printf("\a");printf("Stareled by the sudden sound, sally shouted,");printf("\" By the Great Pukin,what was that! \"\n");return0;}
Stareled by the sudden sound, sally shouted," By the Great Pukin,what was that! "--------------------------------
Process exited after 0.03047 seconds with return value 0
请按任意键继续...
/*习题4:编写一个程序,读入一个浮点数,并分别以小数形式和指数形式打印。*/#include<stdio.h>intmain(void){float num;printf("Please enter a float number:");scanf("%f",&num);printf("Float style: %f exp seyle: %e\n",num,num);return0;}
Please enter a float number:21.29
Float style:21.290001 exp seyle:2.129000e+001--------------------------------
Process exited after 6.786 seconds with return value 0
请按任意键继续...
/习题5:*一年约有3.156*10^7s,编写一个程序,要求输入您的年龄,然后显示该年龄合多少秒。*/#include<stdio.h>intmain(void){int age;float second;printf("请输入您的年龄:");scanf("%d",&age);
second =3.156e7*age;printf("您来到地球已经 %f 秒.\n",second);return0;}
请输入您的年龄:24
您来到地球已经 757440000.000000 秒.--------------------------------
Process exited after 2.964 seconds with return value 0
请按任意键继续...
/*习题6:一个水分子的质量约3.0*10^-23g,1夸脱水大约有950g。编写一个程序,要求输入水的夸脱数,然后显示这么多水中包含多少个水分子。*/#include<stdio.h>intmain(void){float mass =3.0e-23;float mass_quart =950;float quarts;printf("Please enter the number of quart: ");scanf("%f",&quarts);printf("%f quarts of warter contain %e of molucules.\n",quarts,quarts*mass_quart/mass);return0;}
Please enter the number of quart: 10.210.200000 quarts of warter contain 3.230000e+026 of molucules.--------------------------------
Process exited after 2.718 seconds with return value 0
请按任意键继续...
/*习题7:1英寸等于2.54cm。编写一个程序,以厘米单位输入您的身高,然后显示该身高值等于多少英寸。*/#include<stdio.h>intmain(void){float cm;printf("Please enter your height in (cm):");scanf("%f",&cm);printf("Your height in inch is %f.\n",cm/2.54);return0;}
Please enter your height in (cm):177
Your height in inch is 69.685039.--------------------------------
Process exited after 2.141 seconds with return value 0
请按任意键继续...