chapter 03(part)

This commit is contained in:
wandoubaba 2023-12-02 18:47:11 +08:00
parent 0791d4ef04
commit f0fb56c2c8
5 changed files with 71 additions and 0 deletions

11
c03_data/bases.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main(void)
{
int x = 100;
printf("dec = %d; octal = %o; hex = %x\n", x, x, x);
printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x);
return 0;
}

22
c03_data/platinum.c Normal file
View File

@ -0,0 +1,22 @@
/* platinum.c -- your weight in platinum */
#include <stdio.h>
int main(void)
{
float weight; /* 你的体重 */
float value; /* 相等我重量的白金价值 */
printf("你有黄金值钱吗?\n");
printf("试试看吧。\n");
printf("输入你的体重(单位:千克):");
/* 获取用户的输入 */
scanf("%f", &weight);
/* 假设白金的价格是每公斤58124美元*/
value = 475.544 * weight * 1000;
printf("把你换成黄金的话,你这体重值 ¥ %.2f。\n", value);
printf("如果黄金降价了……\n");
printf("那你就多吃点来保值吧,哈哈 ^o^\n");
return 0;
}

14
c03_data/print1.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
int main(void)
{
int ten = 10;
int two = 2;
printf("Doing it right: ");
printf("%d minus %d is %d\n", ten, 2, ten - two);
// printf("Doing it wrong: ");
// printf("%d minus %d is %d\n", ten);
return 0;
}

12
c03_data/print2.c Normal file
View File

@ -0,0 +1,12 @@
/* print2.c -- 更多printf()的特性 */
#include <stdio.h>
int main(void)
{
printf("un = %ld and not %ld\n", 3000000000, 3000000000);
printf("end = %d and %d\n", 200, 200);
printf("big = %ld and not %d\n", 65537, 65537);
printf("verybig = %ld and not %ld\n", 12345678908642, 12345678908642);
return 0;
}

12
c03_data/toobig.c Normal file
View File

@ -0,0 +1,12 @@
#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);
return 0;
}