-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode1.c
101 lines (84 loc) · 1.13 KB
/
code1.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
#include<stdio.h>
#include<stdlib.h>
int main()
{
int r,c;
scanf("%d%d",&r,&c);
double matrix[r][c],ab[r][c+1];
double b[3];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
scanf("%lf",&matrix[i][j]);
}
}
for(int i=0;i<3;i++)
{
scanf("%lf",&b[i]);
//matrix[i][3]=b[i];
}
int j;
for(int i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
ab[i][j]=matrix[i][j];
}
ab[i][j]=b[i];
}
puts("1:");
for(int i=0;i<r;i++)
{
for(int j=0;j<=c;j++)
{
printf("%9.3lf ",ab[i][j]);
}
puts("");
}
// r2 and r3
puts("");
double k,l;
for(int i=0;i<r-1;i++)
{
for(int j=i+1;j<r;j++)
{
k=ab[i][i];
l=ab[j][i];
for(int a=0;a<=c;a++)
{
ab[j][a]=k*ab[j][a]-l*ab[i][a];
ab[i][a]=l*ab[i][a];
//ab[2][i]*=x;
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<=c;j++)
{
printf("%9.3lf ",ab[i][j]);
}
puts("");
}
puts("");
for(int i=0;i<r;i++)
{
l=ab[i][i];
for(int j=0;j<=c;j++)
{
ab[i][j]/=l;
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<=c;j++)
{
printf("%9.3lf ",ab[i][j]);
}
puts("");
}
puts("");
// back substitution
for(int i=0;i
}