1、通过试验的方法(即编写带有此类问题的程序)观察系统如何处理整数上溢、浮点数上溢和浮点数下溢的情况。
#include<stdio.h>
int main(void)
{
unsigned int a=4294967295;
float b=3.4E38;
float c=b*10;
float d=0.1234E-2;
printf("%u+1=%u\n",a,a+1);
printf("%e*10=%e\n",b,c);
printf("%f/10=%f\n",d,d/10);
return(0);
}
2、编写一个程序,要求输入一个ASCII码值(如66),然后输出相应的字符。
#include<stdio.h>
int main(void)
{
char a;
scanf("%d",&a);
printf("%c\n",a);
return(0);
}
3、编写一个程序,发出警报声,并打印下列文字:
Startled by the sudden sound, Sally shouted, "By the Great Pumpkin, what was that!"
#include<stdio.h>
int main(void)
{
printf("\aStartled by the sudden sound,Sally shouted,\"By the Great pumpkin,what was that!\"\n");
return(0);
}
4、编写一个程序,读入一个浮点数,并分别以小数形式和指数形式打印。输出应如同下面格式(实际显示的指数位数也许因系统而不同):
The input is 21.290000 or 2.129000e+001.
#include<stdio.h>
int main(void)
{
float a;
scanf("%f",&a);
printf("The input is %f or %e\n",a,a);
return(0);
}
5、一年约有3.156×l07S。编写一个程序,要求输入您的年龄,然后显示该年龄合多少秒。
#include<stdio.h>
int main(void)
{
float a;
printf("Please input your age:");
scanf("%f",&a);
printf("Your age is %e seconds\n",a*3.156E7);
return(0);
}
6、1个水分子的质量约为3.0×10^-23g,l夸脱水大约有950g。编写一个程序,要求输入水的夸脱数,然后显示这么多水中包含多少个水分子。
#include<stdio.h>
int main(void)
{
float a;
printf("Please input how much quarts the water is:");
scanf("%f",&a);
printf("%f quarts water has %e molecules.\n",a,a*950/3E-23);
return(0);
}
7、1英寸等于2.54cm。编写一个程序,要求输入您的身高(以英寸为单位),然后显示该身高值等于多少厘米。如果您愿意,也可以要求以厘米为单位输入身高,然后以英寸为单位进行显示。
#include<stdio.h>
int main(void)
{
float a;
printf("Please input your height by inches:");
scanf("%f",&a);
printf("Your height is %fcm.\n",a*2.54);
return(0);
}