From 7fd908108aeebec892cf4c48a72e1eee13c72ce1 Mon Sep 17 00:00:00 2001 From: Louise Brown Date: Tue, 25 Oct 2022 09:30:11 +0100 Subject: [PATCH] Changed file structure for LC13,14 and 15 --- .../accessing_via_pointers.c | 0 LC14/LineLength/LineLength.c | 26 +++++++++++++++++++ .../pointer_function_example_1.c | 0 .../pointer_function_example_2.c | 0 .../pointer_to_array_examples.c | 0 .../pointer_to_array_1.c | 0 .../pointer_to_array_2.c | 0 7 files changed, 26 insertions(+) rename C13/{ => AccessingViaPointers}/accessing_via_pointers.c (100%) create mode 100644 LC14/LineLength/LineLength.c rename LC14/{ => PointerFunc1}/pointer_function_example_1.c (100%) rename LC14/{ => PointerFunc2}/pointer_function_example_2.c (100%) rename LC15/{ => PointerToArray}/pointer_to_array_examples.c (100%) rename LC15/{ => PointerToArray1}/pointer_to_array_1.c (100%) rename LC15/{ => PointerToArray2}/pointer_to_array_2.c (100%) diff --git a/C13/accessing_via_pointers.c b/C13/AccessingViaPointers/accessing_via_pointers.c similarity index 100% rename from C13/accessing_via_pointers.c rename to C13/AccessingViaPointers/accessing_via_pointers.c diff --git a/LC14/LineLength/LineLength.c b/LC14/LineLength/LineLength.c new file mode 100644 index 0000000..214d9c2 --- /dev/null +++ b/LC14/LineLength/LineLength.c @@ -0,0 +1,26 @@ +#include +#include +#include + +float LineLength(float x1, float x2, float y1, float y2); + +int main() +{ + float p1x = 3.4, p2x = 5.7, p1y = 0.0, p2y = 6.8; + float length = 0; + length = LineLength(p1x, p2x, p1y, p2y); + printf("Length = %f", length); + return 0; +} + +float LineLength(float x1, float x2, float y1, float y2) +{ + float result; + float dx = x2-x1; + float dy = y2-y1; + float tol = 1e-10; + if (fabs(dx) < tol && fabs(dy) < tol ) + return -1; + result = sqrt(dx*dx + dy*dy); + return result; +} diff --git a/LC14/pointer_function_example_1.c b/LC14/PointerFunc1/pointer_function_example_1.c similarity index 100% rename from LC14/pointer_function_example_1.c rename to LC14/PointerFunc1/pointer_function_example_1.c diff --git a/LC14/pointer_function_example_2.c b/LC14/PointerFunc2/pointer_function_example_2.c similarity index 100% rename from LC14/pointer_function_example_2.c rename to LC14/PointerFunc2/pointer_function_example_2.c diff --git a/LC15/pointer_to_array_examples.c b/LC15/PointerToArray/pointer_to_array_examples.c similarity index 100% rename from LC15/pointer_to_array_examples.c rename to LC15/PointerToArray/pointer_to_array_examples.c diff --git a/LC15/pointer_to_array_1.c b/LC15/PointerToArray1/pointer_to_array_1.c similarity index 100% rename from LC15/pointer_to_array_1.c rename to LC15/PointerToArray1/pointer_to_array_1.c diff --git a/LC15/pointer_to_array_2.c b/LC15/PointerToArray2/pointer_to_array_2.c similarity index 100% rename from LC15/pointer_to_array_2.c rename to LC15/PointerToArray2/pointer_to_array_2.c