From 94dd9d5d745c51a83ccb0a4db8a76c2c6c19e009 Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Sat, 12 Oct 2024 20:42:02 -0600 Subject: [PATCH] vault backup: 2024-10-12 20:42:02 --- .../ECE1400/Chapter 9 Exercises.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/education/software development/ECE1400/Chapter 9 Exercises.md b/education/software development/ECE1400/Chapter 9 Exercises.md index 12cd8df..008bcdf 100644 --- a/education/software development/ECE1400/Chapter 9 Exercises.md +++ b/education/software development/ECE1400/Chapter 9 Exercises.md @@ -1,4 +1,28 @@ > 1. The following function, which computes the area of a triangle, contains two errors. Locate the errors and show how to fix them. (*Hint*: There are no errors in the formula) ```c +double triangle_area(double base, height) +double product; +{ + product = base * height; + return product / 2; +} +``` +Answer: +```c +// A type annotation is needed for `height` +double triangle_area(double base, double height) +{ + // The `product` variable declaration was not in the function block. + double product; + product = base * height; + return product / 2; +} +``` + +> 2. Write a function `check(x, y, n)` that returns `1` if both `x` and `y` fall between zero and `n - 1` inclusive. The function should return 0 otherwise. Assume that `x`, `y`, and `n` are all of type int +```c +int check(int x, int y, int n) { + if (x < 0) +} ``` \ No newline at end of file