diff options
| author | Soikk | 2021-10-25 00:52:13 +0200 |
|---|---|---|
| committer | Soikk | 2021-10-25 00:52:13 +0200 |
| commit | 7603bfcadc6168addbb7a876e3e3f87c45c0a81f (patch) | |
| tree | 7bd013e52c72c0a1deaea00a24ae6b3e0c1da46e /matrix-calculator.c | |
| parent | d1ab35eb7f6cdd400ccc3626d2c010430ec8d126 (diff) | |
| download | soikk-matrix-calculator-main.tar.xz soikk-matrix-calculator-main.tar.zst | |
You can now raise a matrix to a negative power and store the resulting matrixes from an operation with a scalar in another matrix
Diffstat (limited to 'matrix-calculator.c')
| -rw-r--r-- | matrix-calculator.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/matrix-calculator.c b/matrix-calculator.c index a9cebd8..06b90f6 100644 --- a/matrix-calculator.c +++ b/matrix-calculator.c @@ -292,67 +292,97 @@ void matrixCalculator(int input){ printf("What matrix would you like to fill with a number?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to fill matrix %s?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = fillN(matrices[s], n); + matrices[s] = fillN(matrices[d], n); break; case ADD_N: printf("What matrix would you like to add a number to?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to add to matrix %s?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = addN(matrices[s], n); + matrices[s] = addN(matrices[d], n); break; case SUBSTRACT_N: printf("What matrix would you like to substract a number from?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to substract from matrix %s?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = substractN(matrices[s], n); + matrices[s] = substractN(matrices[d], n); break; case MULTIPLY_N: printf("What matrix would you like to multiply by a number?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to multiply matrix %s by?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = multiplyByN(matrices[s], n); + matrices[s] = multiplyByN(matrices[d], n); break; case DIVIDE_N: - printf("What matrix would you like to fill divide by a number?\n"); + printf("What matrix would you like to fill with a number?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to divide matrix %s by?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = divideByN(matrices[s], n); + matrices[s] = divideByN(matrices[d], n); break; case RAISE_TO_N: printf("What matrix would you like to raise to the power of a number?\n"); do{ printf("Matrix A (0), B (1) or C (2)? "); + scanf("%d", &d); + }while(d < 0 || d > 2); + printf("Where would you like to store the resulting matrix?\n"); + do{ + printf("Matrix A (0), B (1) or C (2)? "); scanf("%d", &s); }while(s < 0 || s > 2); printf("With which number would you like to raise matrix %s to?\n", - (s==0)?"A":(s==1)?"B":"C"); + (d==0)?"A":(d==1)?"B":"C"); scanf("%f", &n); - matrices[s] = raiseMatrixToN(matrices[s], n); + matrices[s] = raiseMatrixToN(matrices[d], n); break; case ADD_M: |
