Skip to content

Commit

Permalink
Division with float values.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 8, 2019
1 parent 49b1836 commit 260d1ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ C 语言是一种功能强大、简洁的计算机语言,通过它可以编写
- [使用多个变量](#使用多个变量)
- [简单的计算](#简单的计算)
- [计算吃饼干](#计算吃饼干)
- [有浮点值的除法](#有浮点值的除法)

## 创建第一个程序

Expand Down Expand Up @@ -135,4 +136,21 @@ int main(void)
printf("\n消耗的总能量为 %d 卡路里。\n", total_eaten * cookie_calories);
return 0;
}
```

## [有浮点值的除法](example/division_with_float_values.c)

```c
#include <stdio.h>

int main(void)
{
float plank_length = 10.0f; // 长度
float piece_count = 4.0f; // 多少块
float piece_length = 0.0f; // 每块的长度

piece_length = plank_length / piece_count;
printf("一块 %f 英尺长的木板可以切成 %f 块 %f 英尺长。\n", plank_length, piece_count, piece_length);
return 0;
}
```
12 changes: 12 additions & 0 deletions example/division_with_float_values.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

int main(void)
{
float plank_length = 10.0f; // 长度
float piece_count = 4.0f; // 多少块
float piece_length = 0.0f; // 每块的长度

piece_length = plank_length / piece_count;
printf("一块 %f 英尺长的木板可以切成 %f 块 %f 英尺长。\n", plank_length, piece_count, piece_length);
return 0;
}

0 comments on commit 260d1ba

Please sign in to comment.