chapter 3 done
This commit is contained in:
parent
0b8e953d4b
commit
224dda5a69
15
c03_data/escape.c
Normal file
15
c03_data/escape.c
Normal file
@ -0,0 +1,15 @@
|
||||
/* escape.c - 使用转移序列 */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float salary;
|
||||
|
||||
printf("\aEnter your desired monthly salary:");
|
||||
printf("$______\b\b\b\b\b\b");
|
||||
scanf("%f", &salary);
|
||||
printf("\n\t$%.2f a month is $%.2f a year?", salary, salary * 12.0);
|
||||
printf("\r Gee!\n");
|
||||
|
||||
return 0;
|
||||
}
|
14
c03_data/floaterr.c
Normal file
14
c03_data/floaterr.c
Normal file
@ -0,0 +1,14 @@
|
||||
/* floaterr.c - 演示舍入错误 */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float a, b;
|
||||
|
||||
b = 2.0e20 + 1.0;
|
||||
a = b - 2.0e20;
|
||||
|
||||
printf("%f \n", a);
|
||||
|
||||
return 0;
|
||||
}
|
16
c03_data/showf_pt.c
Normal file
16
c03_data/showf_pt.c
Normal file
@ -0,0 +1,16 @@
|
||||
/* showf_pt.c - 以两种方式显示float类型的值 */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float aboat = 32000.0;
|
||||
double abet = 2.14e9;
|
||||
long double dip = 5.32e-5;
|
||||
|
||||
printf("%f can be written %e\n", aboat, aboat);
|
||||
printf("And it's %a in hexadecimal, powers of a notation\n", aboat);
|
||||
printf("%f can be written %e\n", abet, abet);
|
||||
printf("%Lf can be written %Le\n", dip, dip);
|
||||
|
||||
return 0;
|
||||
}
|
15
c03_data/typesize.c
Normal file
15
c03_data/typesize.c
Normal file
@ -0,0 +1,15 @@
|
||||
/* typesize.c - 打印类型大小 */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// %zd 用于打印size_t类型的值。sizeof(int) 返回一个 size_t 类型的值,表示 int 类型变量的大小(以字节为单位)。
|
||||
printf("Type int has a size of %zd bytes.\n", sizeof(int));
|
||||
printf("Type char has a size of %zd bytes.\n", sizeof(char));
|
||||
printf("Type long has a size of %zd bytes.\n", sizeof(long));
|
||||
printf("Type long long has a size of %zd bytes.\n", sizeof(long long));
|
||||
printf("Type double has a size of %zd bytes.\n", sizeof(double));
|
||||
printf("Type long double has a size of %zd bytes.\n", sizeof(long double));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user