Merge pull request #6 from SinusFox/tasks-6-and-7

Tasks 6 and 7
This commit is contained in:
SinusFox
2023-05-30 00:38:40 -07:00
committed by GitHub
2 changed files with 74 additions and 0 deletions
@@ -0,0 +1,58 @@
#include <stdio.h>
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;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
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;
}