From 0ceddeb021e1f7deaae39fb5c1625a436ddb521b Mon Sep 17 00:00:00 2001 From: SinusFox Date: Tue, 30 May 2023 09:37:38 +0200 Subject: [PATCH 1/2] task 6 --- .../6_Yet_Another_Simple_Calculator.c | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 6_Yet_Another_Simple_Calculator/6_Yet_Another_Simple_Calculator.c diff --git a/6_Yet_Another_Simple_Calculator/6_Yet_Another_Simple_Calculator.c b/6_Yet_Another_Simple_Calculator/6_Yet_Another_Simple_Calculator.c new file mode 100644 index 0000000..2330b32 --- /dev/null +++ b/6_Yet_Another_Simple_Calculator/6_Yet_Another_Simple_Calculator.c @@ -0,0 +1,58 @@ +#include + +void out(double* number) { + printf("The result is %lf.", *number); +} + +int main() { + // vars + double numOne = 0, numTwo = 0, numOut = 0; + char cancel, operation; + + // main loop + do { + // input for calculation + printf("Please type in the first number: "); + scanf("%lf", &numOne); + fflush(stdin); + printf("\nPlease type in the operation (+/-/*/:): "); + scanf("%c", &operation); + fflush(stdin); + printf("Please type in the second number: "); + scanf("%lf", &numTwo); + fflush(stdin); + + // calculations + switch (operation) { + case '+': // add + numOut = numOne + numTwo; + out(&numOut); + break; + case '-': // subtract + numOut = numOne - numTwo; + out(&numOut); + break; + case '*': // multiply + numOut = numOne * numTwo; + out(&numOut); + break; + case ':': // divide + if (numTwo != 0) { + numOut = numOne / numTwo; + out(&numOut); + } else { + printf("\nSecond number can't be 0."); + } + break; + default: // other -> invalid operation + printf("\nInvalid operation."); + } + + // input 'q' if programm should be exited + printf("\nWould you like to enter another calculation? (any other key = continue, q = quit): "); + scanf("%c", &cancel); + fflush(stdin); + } while (cancel != 'q'); // end of do-while-loop + + return 0; +} From 8c5a52eedd7a8a5baba109b1789141f1531ab63b Mon Sep 17 00:00:00 2001 From: SinusFox Date: Tue, 30 May 2023 09:37:47 +0200 Subject: [PATCH 2/2] task 7 --- 7_Matrix_1x1/7_Matrix_1x1.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 7_Matrix_1x1/7_Matrix_1x1.c diff --git a/7_Matrix_1x1/7_Matrix_1x1.c b/7_Matrix_1x1/7_Matrix_1x1.c new file mode 100644 index 0000000..5a54552 --- /dev/null +++ b/7_Matrix_1x1/7_Matrix_1x1.c @@ -0,0 +1,16 @@ +#include + +int main() { + // setting the end of the array + int upTo = 20; + + // printing the values as matrix + for (int i = 1; i <= upTo; i++) { // y axis + for (int j = 1; j <= upTo; j++) { // x axis + printf("%5i", (i*j)); // printing each value, i*j = the value + } + printf("\n"); // end of line on x axis + } + + return 0; +}