1.
#include<stdio.h>
int main(void)
{
//整数上溢
int i = 2147483647;
unsigned int j = 4294967295;
printf("%d %d %d\n", i, i + 1, i + 2);
printf("%u %u %u\n", j, j + 1, j + 2);
//浮点数上溢
float k = 3.4E38;
printf("%f\n", k*100.0f);
//浮点数下溢
float c, d;
c = 1.4E-45;
d = 1.4E-45 / 2;
printf("c = %e\n", c);
printf("d = %e\n", d);
return(0);
}
2.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
int a;
printf("please enter an ASCII number:");
scanf("%d", &a);
printf("the number %d is %c\n", a,a);
return(0);
}
3.
#include<stdio.h>
int main(void)
{
printf("\aStartled by the sudden sound,Sally shouted,\n");
printf("\"By the Great Pumpkin,what was that!\"\n");
return(0);
}
4
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
float a;
printf("Enter a floating-point value:");
scanf("%f", &a);
printf("fixed-point notation:%f\n", a);
printf("exponential notation:%e\n", a);
printf("p notation:%a\n", a);
return(0);
}
5
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
int age;
printf("Please enter your age:");
scanf("%d", &age);
printf("the age %d is %fs\n", age, age*3.156e07);
return(0);
}
6
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
int water;
double weight;
printf("请输入水的夸脱数:");
scanf("%d", &water);
weight = water * 950 / 3.0e-23;
printf("the %d water is %e weight",water,weight);
return(0);
}
7
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
float inches;
float high;
printf("请输入身高(英寸):");
scanf("%f", &inches);
high = 2.54*inches;
printf("the %f inches is %f high",inches,high);
return(0);
}
8
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
float cups,pint, ounce, soup_spoon, tea_spoon;
printf("please enter the cups:");
scanf("%f", &cups);
pint = cups/ 2.0;
ounce = 8.0*cups;
soup_spoon = 8.0*cups*2.0;
tea_spoon = 8.0*cups*2.0*3.0;
printf("%fcups is %fpint\n %founce\n %fsoup_spoon\n %ftea_spoon\n", cups, pint, ounce, soup_spoon, tea_spoon);
return(0);
}