From 4b798bfc66316359ebbc2c9d13af027be02f833d Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Fri, 6 Oct 2023 13:58:30 +0100 Subject: [PATCH] c10e1-3 --- C10/ex2.c | 19 +++++++++++++++++++ C10/ex3.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 C10/ex2.c create mode 100644 C10/ex3.c diff --git a/C10/ex2.c b/C10/ex2.c new file mode 100644 index 0000000..ea510fe --- /dev/null +++ b/C10/ex2.c @@ -0,0 +1,19 @@ +#include +#include + + +float degrees_to_radians(float degrees) { + return M_PI * degrees / 180.0; +} + +int main() { + float input, output; + printf("Enter an angle in degrees: "); + scanf("%f", &input); + + output = degrees_to_radians(input); + + printf("%f radians\n", output); + + return 0; +} diff --git a/C10/ex3.c b/C10/ex3.c new file mode 100644 index 0000000..d633fb5 --- /dev/null +++ b/C10/ex3.c @@ -0,0 +1,36 @@ +#include +#include + + +float degrees_to_radians(float degrees) { + return M_PI * degrees / 180.0; +} + + +int main() { + int rc, start, end; + + printf("Start: "); + rc = scanf("%d", &start); + if (rc != 1) { + printf("Please enter a real integer\n"); + return 1; + } + printf("End: "); + rc = scanf("%d", &end); + if (rc != 1) { + printf("Please enter a real integer\n"); + return 1; + } + + if (start > end) { + printf("Please ensure that start value is smaller than end value\n"); + return 1; + } + + for (int i = start; i <= end; i++) { + printf("%d %f\n", i, degrees_to_radians((float)i)); + } + + return 0; +}