Skip to content

Correct solution for exercise 10 chapter 2 #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions 02/exercises/10/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ In the `dweight.c` program (Section 2.4), which spaces are essential?

### Solution
Below is the complete `dweight.c` program, as written in Section 2.4:

```c
/* Computes the dimensional weight of a 12" x 10" x 8" box */

Expand All @@ -25,6 +26,17 @@ int main(void)
return 0;
}
```
The only spaces which are necessary are the line break in the `#include`
directive and its space between `#include` and `<stdio.h>` as well as the space
between `return` and `0`.

The only necessary spaces are:

- the line break in the `#include` directive;
- the space between the `int` declaration and the main function;
- the space between the `int` declaration and the `height` variable;
- the space between `return` and `0`.

Indeed, without all "unnecessary" spaces the programme would be:

```c
#include<stdio.h>
int main(void){int height,length,width,volume,weight;height=8;length=12;width=10;volume=height*length*width;weight=(volume+165)/166;printf("Dimensions: %dx%dx%d\n",length,width,height);printf("Volume (cubic inches): %d\n",volume);printf("Dimensional weight (pounds): %d\n",weight);return 0;}
```