c-labs/lab-3/lab_3_description.md

169 lines
2 KiB
Markdown

# Lab 3 - Fancy shapes
In this lab we'll be focusing on the C programming aspect. This will cover
for-loops and if-statements. To practice these we'll be drawing some shapes in
the terminal!
The input will be one of the following numbers, passed through argv:
1. A square
2. A triangle
3. An inverted triangle (upside down)
4. A diamond
Your program will take in 2 arguments. The first is a number between 1 and 4,
indicating which of the shapes listed above you'll be printing. The second
argument is a number indicating the _largest horizontal width_ of the shape. For
example, for a triangle, this'll be the width of the base.
Your program will print the indicated shape at the indicated dimensions. Write
your code in a `main.c` file, then run `bash check.sh main.c` to test your code.
## Examples
#### Example 1
```
./a.out 1 4
```
Output:
```
$$$$
$$$$
$$$$
$$$$
```
#### Example 2
```
./a.out 1 10
```
Output:
```
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
```
#### Example 3
```
./a.out 2 6
```
Output:
```
$$
$$$$
$$$$$$
```
Notice how with an even number for the width, will result with 2 at the top, not
one.
#### Example 4
```
./a.out 2 7
```
Output:
```
$
$$$
$$$$$
$$$$$$$
```
#### Example 5
```
./a.out 3 14
```
Output:
```
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
```
#### Example 6
```
./a.out 4 14
```
Output:
```
$$
$$$$
$$$$$$
$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
```
#### Example 7
```
./a.out 4 15
```
Output:
```
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$
$$$$$$$
$$$$$
$$$
$
```
## Testing
Run the following command to test your work:
```
bash check.sh main.c
```
If the output doesn't say you passed, your program has a bug. Fix it and then
try again.