-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussianLab.c
63 lines (53 loc) · 1.28 KB
/
GaussianLab.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
#include <stdio.h>
int main()
{
float mat[4][5] = {
{1, -1, 2, -1, -8},
{2, -2, 3, -3, -20},
{1, 1, 1, 0, -2},
{1, -1, 4, 3, 4}};
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
printf("%.2f\t", mat[i][j]);
}
printf("\n");
}
float arr[4];
for (int i = 1; i < 4; i++)
{
arr[i] = mat[i][0];
printf("%.2f ", mat[i][0]);
}
printf("\n\n");
for (int i = 1; i < 4; i++)
{
for (int j = i; j < 4; j++)
{
if (i == j && mat[i][j] == 0)
{
for (int k = 0; k < 5; k++)
{
float temp = mat[i + 1][k];
mat[i + 1][k] = mat[i][k];
mat[i][k] = temp;
}
}
for (int k = i - 1; k < 5; k++)
{
mat[j][k] = (mat[i - 1][i - 1] / mat[j][i - 1]) - mat[j][k];
}
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
printf("%.2f\t", mat[i][j]);
}
printf("\n");
}
printf("\n\n");
}
return 0;
}