-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
776 lines (726 loc) · 24.9 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/*
LICENCE
Provided with an MIT Licence and Licenced as Share-Alike CC 6/5/2020
NAME
Keyboard Math '75
DEPENDENCIES
You must add constant.h to your project
DESCRIPTION
This file is used for testing linear algebraic algorithms, and describing the
most fundamental aspects of computing bidimentional arrays. This simple application
program is intended as starting point for more complex algorithms involving arrays
and linear algebra. This application performs only the fundamentals and computes
under the standard practice of functional programming.
ASSIGNMENT
Assignment Type: Final Project
Course: Programming Logic
Date: 6/4/2020
RUN
gcc main.c -o m
MODIFIED
* Created 5 Jun 2020 Michaus M. , &. Romero M.A.;
*/
/***********************************************************/
/***********************************************************/
/***********************************************************/
/*
Declaration of Include files
*/
#include <stdio.h> // access terminal
#include <stdlib.h> // access system
#include <stdbool.h> // boolean variables
#include <string.h> // string functions
#include "constants.h" // constants
/*
Declaration of Global Variables
*/
float res[11][11]; // (global) ANS as matrix
float sys[11][11]; // (global) ANS as system
float matrix_a[11][11]; // (global) matrix A
float matrix_b[11][11]; // (global) matriz B
int mn = 0; // (global) current size of matrix
bool is_valid_a = false; // (global) matrix is usable
bool is_valid_b = false; // (global) matrix is usable
/************* START FUNCTION DECLARATIONS ***************/
/**********************************************************/
int KM75_printTitle(bool skip);
char KM75_scanSelect(const char *text, const int size);
float KM75_scanNumber(const char *text, bool int_only);
char KM75_listSelect(const char *texts[], const int size);
void KM75_exitApp(const char *text);
int KM75_arraySizer(bool edit_mn);
int KM75_arrayEditor(bool zero_only, float argv[11][11]);
int KM75_arrayMenu(bool is_a);
int KM75_arrayPrinter(bool is_sys, float argv_mat[11][11]);
int KM75_arrayDot(float argv_a[11][11], float argv_b[11][11]);
int KM75_arraySum(float argv_a[11][11], float argv_b[11][11]);
int KM75_arrayMemcpy(float argv_des[11][11], float argv_srs[11][11]);
int KM75_scanConstants(float argv_des[11][11], float argv_src[11][11]);
int KM75_arraySwapRow(float argv_des[11][11], int r1, int r2);
int KM75_arraySwapCol(float argv_des[11][11], int c1, int c2);
int KM75_arrayBkwdSubs(float argv_des[11][11], float argv_src[11][11]);
int KM75_arrayGaussian(float argv_des[11][11], float argv_src[11][11]);
float KM75_diagonalProduct(float argv_src[11][11]);
int KM75_arrayCramer(float argv_des[11][11], float argv_src[11][11]);
int KM75_arraySarrus(float argv_src[11][11]);
int KM75_arrayTranspose(float argv_des[11][11], float argv_src[11][11]);
bool KM75_appBootstrapper(bool by_passing, char option);
/***********************************************************/
/***********************************************************/
/***********************************************************/
/*
* $console KM75_printTitle
* This block will print ACSII art with a neat title just below, all lines are printed to welcome the user.
* Time complexity: O(1).
*
* @return int 0: this block returns 0 when it ends its execution
*/
int KM75_printTitle(bool skip)
{
if (!skip)
{
printf("\n");
printf("\n");
printf("\t ::.----.` `.---..:////:-. \n");
printf("\t ymh-:::::- -:::::-dmmmmmmmmds: \n");
printf("\t ymm::::::: `````` .-::::/+ohmmd: \n");
printf("\t ymm::::::: ` `-:::::-/hmmo \n");
printf("\t ymm::::::: .:- .::::::-hmm/\n");
printf("\t ymm::::::: -:::-o- .:::::::mmy\n");
printf("\t ymm::::::: `-:::-syy- :::::::mmy\n");
printf("\t ymm::::::: `:::::yyyy. :::::::mmy\n");
printf("\t ymm::::::: .::-/yyyy- :::::::mmy\n");
printf("\t ymm:::::::` --/yyys. :::::::mmy\n");
printf("\t omms-::::::` :yyo` :::::::mmy\n");
printf("\t `hmmo-::::::. .+` :::::::mmy\n");
printf("\t `smmdo/--:::-.` :::::::mmy\n");
printf("\t -sdmmdhyyyyyy-:::::: ::::::-dmy\n");
printf("\t `-+osyyyys/-::::-` .-:::-:oo\n");
printf("\n");
printf("\t :::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\t :: KEYBOARD MATH '75 ::\n");
printf("\t :::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\n");
printf("\n");
system("pause");
}
return 0;
}
/*
* $console KM75_scanSelect
* This function will read and validate the user's input as a character, and then flush stdin. An invalid input means this function will return SELECT_INVALID.
* Time complexity: unknown.
*
* @param char *text: string to print before scanning input
* @param int size: the count of allowed inputs starting from Aa
* @return char scanned or SELECT_INVALID;
*/
char KM75_scanSelect(const char *text, const int size)
{
char scanned[1];
printf("\n %s", text);
fgets(scanned, 2, stdin);
char selected = (char)scanned[0];
selected = ((int)selected >= 97 && (int)selected < 97 + size) || ((int)selected >= 65 && ((int)selected < 65 + size))
? selected
: SELECT_INVALID;
if (selected == SELECT_INVALID)
{
printf("%s \n", SELECT_INVALID_TEXT);
}
fflush(stdin);
return selected;
}
/*
* $console KM75_scanNumber\
* This function is a mirrored <<KM75_scanSelect>>, it will read and validate input as an integer number, and then flush stdin. An invalid input means this function will return 0.
* Time complexity: unknown.
*
* @param char *text: string to print before scanning input
* @return int scanned or 0
*/
float KM75_scanNumber(const char *text, bool int_only)
{
char scanned[10000];
printf("\n %s", text);
fgets(scanned, 10001, stdin);
float selected = int_only ? (float)atoi(scanned) : atof(scanned);
fflush(stdin);
return selected;
}
/*
* $console KM75_listSelect
* This function will list options from {texts} to the user through the process' console as a list, and capture the selected option as a char, if an invalid choice is detected a loop is performed.
* Time complexity: unknown.
*
* @param char *texts[] : the menu as an array of strings,
* @param int size : sizeof *texts[].
* @return select char : selected option.
*/
char KM75_listSelect(const char *texts[], const int size)
{
printf("\n");
for (int i = 0; i < size; i++)
printf("%s \n", texts[i]);
char selected = SELECT_INVALID;
while (selected == SELECT_INVALID)
selected = KM75_scanSelect(SELECT_TEXT, MENU_SIZE);
return selected;
}
/*
* $console KM75_exitApp
* Will pause the execution system and then close the main thread therefore terminating the execution process.
* Time complexity: unknown.
*
* @param char *text : the text to print when closing
* @return void: the app closes within this block
*/
void KM75_exitApp(const char *text)
{
printf("\n%s, ", text);
system("pause");
exit(0);
}
/*
* $console KM75_arraySizer
* This block will return the captured current global matrix size, validate for a minimum allowed and maximum allowed and loop until the captured value is valid.
* Time complexity: O(1).
*
* @param bool edit_mn : true to read input mn or false for default
* @param bool is_m : true to scan for M or false for N
* @return int mn : valid size of mn
*/
int KM75_arraySizer(bool edit_mn)
{
bool mn_invalid = true;
int mn = MAX_MATRIX_SIZE;
while (mn_invalid)
{
if (edit_mn)
{
mn = (int)KM75_scanNumber(INPUT_MATRIX_SIZE, true);
if (mn <= MAX_MATRIX_SIZE && mn >= MIN_MATRIX_SIZE)
mn_invalid = false;
else
printf("\n %s%i", ERROR_MATRIX_SIZE, MAX_MATRIX_SIZE);
}
else
mn_invalid = false;
}
return mn;
}
/*
* $console KM75_arrayEditor
* This function will zero selected matrixes or capture matrix data from the user.
* Time complexity: O(N^2).
*
* @param bool fill_only : if true block will reset the selected array to a zeroed array
* @param bool fill_only : if true block will edit a, otherwise false it will edit b
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayEditor(bool zero_only, float argv[11][11])
{
if (!zero_only)
printf("\n %s \n", EDIT_MATRIX_TEXT);
int aux_mn = mn;
mn = mn == 0 ? KM75_arraySizer(!zero_only) : mn; // O(1) ~ O(0)
for (int i = 0; i < mn; i++)
for (int j = 0; j < mn; j++)
{
char text[255];
snprintf(text, sizeof(text), "[%i,%i]: ", i, j);
argv[i][j] = zero_only ? 0 : KM75_scanNumber(text, false);
}
if (zero_only)
mn = !is_valid_a && !is_valid_b ? 0 : aux_mn;
return 0;
}
/*
* $exec KM75_arrayMenu
* This function bootstraps all other important functions to edit arrays, validates said arrays and executes selected blocks.
* Time complexity: O(2N^2).
*
* @param bool is_a : if true this block will let the user define matrix a, if false matrix b
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayMenu(bool is_a)
{
bool wants_to_continue = true;
if ((is_valid_a && is_a) || (is_valid_b && !is_a))
{
printf("\n %s \n", RESET_MATRIX_WARNING);
char selected_continue = KM75_listSelect(CONTINUE_LIST, CONTINUE_SIZE);
wants_to_continue = selected_continue == 'a' || selected_continue == 'A';
}
if (wants_to_continue)
{
if ((is_valid_a && is_a) || (is_valid_b && !is_a))
{
is_valid_a = false;
is_valid_b = false;
mn = 0;
KM75_arrayEditor(true, matrix_a);
KM75_arrayEditor(true, matrix_b);
}
KM75_arrayEditor(true, is_a ? matrix_a : matrix_b); //O(N^2)
KM75_arrayEditor(false, is_a ? matrix_a : matrix_b); //O(N^2)
if (is_a)
is_valid_a = true;
else
is_valid_b = true;
}
return 0;
}
/*
* $console KM75_arrayPrinter
* This function may be called to print a matrix, the selected matrix will be logged with its corresponding columns, rows and spaces.
* Time complexity: O(N^2 + N).
*
* @param bool is_res : if true this block will print the res matrix
* @param bool is_a : if true this block will print matrix a, if false matrix b
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayPrinter(bool is_sys, float argv_mat[11][11])
{
printf("\n%s\n", is_sys ? PRINT_RES_TEXT : PRINT_MATRIX_TEXT); //O(1)
printf("\n"); //O(1)
for (int i = 0; i < mn; i++)
{
char var = (char)(97 + i);
if (is_sys)
printf("%c: %.2f", var, argv_mat[i][0]); // O(1)
for (int j = 0; j < mn; j++)
if (!is_sys)
printf("%.2f ", argv_mat[i][j]); // O(1)
printf("\n"); // O(1)
}
return 0;
}
/*
* $exec KM75_arrayDot
* This function will perform a matmul operation of two matrixes, matrixes a and b (Global Variables), using Eric Weiser's method.
* Time complexity: O(N^3 + 2N^2 + N).
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayDot(float argv_a[11][11], float argv_b[11][11])
{
float argv_res[11][11];
printf("\n%s\n", DOT_MATRIX_TEXT); //O(1)
float aux;
KM75_arrayEditor(true, argv_res); //O(N^2)
for (int i = 0; i < mn; i++)
for (int j = 0; j < mn; j++)
{
aux = 0;
for (int k = 0; k < mn; ++k)
aux += argv_a[i][k] * argv_b[k][j];
argv_res[i][j] = aux;
}
KM75_arrayPrinter(false, argv_res); //O(N^2 + N)
return 0;
}
/*
* $exec KM75_arraySum
* This function performs a sum of two matrixes, namely a and b (Global Variables).
* Time complexity: O(3N^2 + N + 1).
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arraySum(float argv_a[11][11], float argv_b[11][11])
{
float argv_res[11][11];
printf("\n%s\n", SUM_MATRIX_TEXT); //O(1)
KM75_arrayEditor(true, argv_res); // O(N^2)
for (int i = 0; i < mn; i++)
for (int j = 0; j < mn; j++)
argv_res[i][j] = argv_a[i][j] + argv_b[i][j];
KM75_arrayPrinter(false, argv_res); // O(N^2 + N + 1)
return 0;
}
/*
* $exec KM75_arrayMemcpy
* This block performs a memcpy operation. similar to numpy's for phyton, res recieves all values stored in matrix a.
* Time complexity: O(N^2)
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayMemcpy(float argv_des[11][11], float argv_srs[11][11])
{
for (int i = 0; i < 11; i++)
for (int j = 0; j < 11; j++)
argv_des[i][j] = argv_srs[i][j];
return 0;
}
/*
* $exec KM75_scanConstants
* This block adds an extra column to res with a set of defined constants, procedural linear equations are calculated here.
* Time complexity: unknown.
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_scanConstants(float argv_des[11][11], float argv_src[11][11])
{
KM75_arrayMemcpy(argv_des, argv_src);
for (int i = 0; i < mn; i++)
{
char text[255] = "";
for (int j = 0; j < mn; j++)
{
char var = (char)(97 + j);
char partial[20];
if (j == 0)
snprintf(partial, sizeof(partial), "(%.2f%c)", argv_des[i][j], var);
else if (j == (mn - 1))
{
snprintf(partial, sizeof(partial), " %c (%.2f%c) %c ", '+', argv_des[i][j], var, '=');
}
else
snprintf(partial, sizeof(partial), " %c (%.2f%c)", '+', argv_des[i][j], var);
strcat(text, partial);
}
argv_des[i][mn] = KM75_scanNumber(text, false);
}
return 0;
}
/*
* $exec KM75_arraySwapRow
* This block swaps instructed rows from {{res}}, so basically r1 and r2 swap positions inside the array.
* Time complexity: O(N).
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arraySwapRow(float argv_des[11][11], int r1, int r2)
{
float aux;
for (int i = 0; i <= mn; i++)
{
aux = argv_des[r2][i];
argv_des[r2][i] = argv_des[r1][i];
argv_des[r1][i] = aux;
}
return 0;
}
/*
* $exec KM75_arraySwapCol
* This block swaps instructed columns from {{res}}, so basically c1 and c2 swap positions inside the array.
* Time complexity: O(N).
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arraySwapCol(float argv_des[11][11], int c1, int c2)
{
float aux;
for (int i = 0; i <= mn; i++)
{
aux = argv_des[i][c2];
argv_des[i][c2] = argv_des[i][c1];
argv_des[i][c1] = aux;
}
return 0;
}
/*
* $exec KM75_arrayTraingular
* This block expects {{res}} to be a square matrix with an extra column of defined constants <<res[mn-1][mn] is defined>>. This block will swap rows and perform other matrix operations to zero all numbers below {{res}}'s main diagonal. If the main diagonal has a row with a zeroed pivot that cannot be swapped for another row then this system returns the index of said pivot.
* Time complexity: O(N^3).
*
* @return int -1 : this block returns -1 when the system can be solved, otherwise return an index of a zeroed pivot which will cause infinitely many solutions or no solutions at all.
*/
int KM75_arrayTraingular(float argv_des[11][11])
{
for (int i = 0; i < mn; i++)
{
int max_pivot_index = i;
int max_pivot_value = argv_des[max_pivot_index][i];
for (int j = i + 1; j < mn; j++)
if (abs(argv_des[j][i]) > max_pivot_value)
max_pivot_value = argv_des[j][i], max_pivot_index = j;
if (!argv_des[i][max_pivot_index])
return i;
if (max_pivot_index != i)
KM75_arraySwapRow(argv_des, i, max_pivot_index);
for (int j = i + 1; j < mn; j++)
{
float elem = argv_des[j][i] / argv_des[i][i];
for (int k = i + 1; k <= mn; k++)
argv_des[j][k] -= argv_des[i][k] * elem;
argv_des[j][i] = 0;
}
}
return -1;
}
/*
* $exec KM75_arrayBkwdSubs
* This block expects res to be a square matrix with an extra column of defined constants <<res[mn-1][mn] is defined>>, res must be in an upper triangular form. This block will take the bottom most system wich will only have one constant and one variable and start remplacing values upwards.
* Time complexity: O(N^2).
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayBkwdSubs(float argv_des[11][11], float argv_src[11][11])
{
for (int i = mn - 1; i >= 0; i--)
{
argv_des[i][0] = argv_src[i][mn];
for (int j = i + 1; j < mn; j++)
argv_des[i][0] -= argv_src[i][j] * argv_des[j][0];
argv_des[i][0] = argv_des[i][0] / argv_src[i][i];
}
return 0;
}
/*
* $exec KM75_arrayGaussian
* This function will execute other blocks, related to gaussian elimination. And predict if the system of equations can or cannot be solved.
* Time complexity: unknown.
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayGaussian(float argv_des[11][11], float argv_src[11][11])
{
float mem[11][11];
KM75_arrayEditor(true, mem);
printf("\n%s\n", GAUSSIAN_MATRIX_TEXT); //O(1)
KM75_scanConstants(mem, argv_src);
int principal_index_zeroed = KM75_arrayTraingular(mem);
if (principal_index_zeroed != -1)
{
if (mem[principal_index_zeroed][mn])
printf("\n%s\n", MATRIX_INCONSISTANT);
else
printf("\n%s\n", MATRIX_INFINITE);
return 0;
}
KM75_arrayBkwdSubs(argv_des, mem);
KM75_arrayPrinter(true, argv_des);
return 0;
}
/*
* $exec KM75_arraySarrus
* This block finds the determinant of a matrix, matrix needs to be squared <<nxn>> and n must be smaller or equal than 3.
* Time complexity: O(N^2 + N)
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arraySarrus(float argv_src[11][11])
{
float argv_des[11][11];
KM75_arrayMemcpy(argv_des, argv_src);
if (mn > 3)
{
printf("\n%s\n", ERROR_MATRIX_SARRUS);
return 0;
}
float d1 = 0, d2 = 0, d = 0;
if (mn == 3)
for (int i = 0; i < 3; i++)
{
d1 = d1 + argv_des[0][i] * argv_des[1][(i + 1) % 3] * argv_des[2][(i + 2) % 3];
d2 = d2 + argv_des[2][i] * argv_des[1][(i + 1) % 3] * argv_des[0][(i + 2) % 3];
}
d = d1 - d2;
if (mn == 2)
d = (argv_des[0][0] * argv_des[1][1]) - (argv_des[1][0] * argv_des[0][1]);
printf("\n%s %.2f\n", PRINT_RES_TEXT, d);
return d;
}
/*
* $exec KM75_arrayTranspose
* This block swaps rows as columns from a provided matrix {{a}} into {{res}}.
* Time complexity: O(N^2 + N)
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayTranspose(float argv_des[11][11], float argv_src[11][11])
{
for (int i = 0; i < mn; ++i)
for (int j = 0; j < mn; ++j)
argv_des[j][i] = argv_src[i][j];
KM75_arrayPrinter(false, argv_des);
return 0;
}
/*
* $exec KM75_diagonalProduct
* This block finds the determinant of a traingular matrix, matrix needs to be squared <<nxn>>.
* Time complexity: O(N)
*
* @return int det : this block returns det when it ends its execution
*/
float KM75_diagonalProduct(float argv_src[11][11])
{
float det = 1;
for (int i = 0; i < mn; i++)
det *= argv_src[i][i];
return det;
}
/*
* $exec KM75_arrayCramer
* This function will execute other blocks, related to cramer's rule. And predict if the system of equations can or cannot be solved.
* Time complexity: unknown.
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int KM75_arrayCramer(float argv_des[11][11], float argv_src[11][11])
{
float res[11][11];
float ds = 0;
printf("\n%s\n", CRAMER_MATRIX_TEXT); //O(1)
KM75_arrayEditor(true, res);
KM75_scanConstants(res, argv_src);
for (int i = 0; i <= mn; i++)
{
float aux[11][11];
KM75_arrayMemcpy(aux, res);
if (i != 0)
KM75_arraySwapCol(aux, i - 1, mn);
int principal_index_zeroed = KM75_arrayTraingular(aux);
if (principal_index_zeroed != -1)
{
if (aux[principal_index_zeroed][mn])
printf("\n%s\n", MATRIX_INCONSISTANT);
else
printf("\n%s\n", MATRIX_INFINITE);
return 0;
}
argv_des[i == 0 ? mn : i - 1][0] = KM75_diagonalProduct(aux);
}
for (int i = 0; i < mn; i++)
argv_des[i][0] /= argv_des[mn][0];
KM75_arrayPrinter(true, argv_des);
}
/*
* $bootstrap KM75_appBootstrapper
* This function bootstraps all other important functions, executes selected blocks.
* Time complexity: unknown, execution time is completely user dependant.
*
* @return bool wants_to_continue : returns true to repeat
*/
bool KM75_appBootstrapper(bool by_passing, char option)
{
char selected_menu = option;
if (!by_passing)
{
selected_menu = KM75_listSelect(
!is_valid_a ? A_MENU_LIST
: !is_valid_b ? B_MENU_LIST
: MENU_LIST,
MENU_SIZE);
}
system("cls");
switch (selected_menu)
{
case 'a':
case 'A':
KM75_arrayMenu(true);
break;
case 'b':
case 'B':
KM75_arrayMenu(false);
break;
case 'c':
case 'C':
if (!is_valid_a)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayPrinter(false, matrix_a);
break;
case 'd':
case 'D':
if (!is_valid_b)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayPrinter(false, matrix_b);
break;
case 'e':
case 'E':
if (!is_valid_a)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayGaussian(sys, matrix_a);
break;
case 'f':
case 'F':
if (!is_valid_a)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayCramer(sys, matrix_a);
break;
case 'g':
case 'G':
if (!is_valid_a)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arraySarrus(matrix_a);
break;
case 'h':
case 'H':
if (!is_valid_a)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayTranspose(res, matrix_a);
break;
case 'i':
case 'I':
if (!is_valid_a || !is_valid_b)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arrayDot(matrix_a, matrix_b);
break;
case 'j':
case 'J':
if (!is_valid_a || !is_valid_b)
{
printf("\n %s \n", DISABLED_WARNING);
return true;
}
KM75_arraySum(matrix_a, matrix_b);
break;
case 'k':
case 'K':
KM75_exitApp(EXIT_TEXT);
return false;
break;
default:
printf("%s, %s", ERROR_TEXT, EXIT_TEXT);
return false;
break;
}
char selected_continue = KM75_listSelect(CONTINUE_LIST, CONTINUE_SIZE);
bool wants_to_continue = selected_continue == 'a' || selected_continue == 'A';
if (!wants_to_continue)
KM75_exitApp(EXIT_TEXT);
system("cls");
return wants_to_continue;
}
/*
* $main main
* This is the app's main function and it will loop the execution of KM75_appBootstrapper until appBootsrapper returns false.
* Time complexity: unknown, execution time is completely user dependant.
*
* @return int 0 : this block returns 0 when it ends its execution
*/
int main()
{
KM75_printTitle(false);
bool can_repeat = true;
while (can_repeat)
{
can_repeat = KM75_appBootstrapper(false, SELECT_INVALID);
}
return 0;
}
/*
End of program
*/