forked from skb1129/nmst-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgauss-seidal.cpp
More file actions
46 lines (46 loc) · 814 Bytes
/
Copy pathgauss-seidal.cpp
File metadata and controls
46 lines (46 loc) · 814 Bytes
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
#include<iostream>
using namespace std;
class matrix{
float m[99][100],var[100]={0};
int n,i,j;
public:
void input(){
cout<<"Enter the number of equations : ";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter the constants of equation "<<i+1<<endl;
for(j=0;j<=n;j++){
cin>>m[i][j];
}
}
cout<<"Enter the initial value of variables"<<endl;
for(i=0;i<n;i++){
cin>>var[i];
}
}
void display(){
for(i=0;i<n;i++){
cout<<var[i]<<endl;
}
}
void iterate(){
for(i=0;i<n;i++){
var[i]=m[i][n]/m[i][i];
for(j=0;j<n;j++){
if(i!=j)
var[i]=var[i]-m[i][j]*var[j]/m[i][i];
}
}
}
};
int main(){
int itr,i;
matrix mat;
mat.input();
cout<<"Enter the number of iterations : ";
cin>>itr;
for(i=0;i<itr;i++){
mat.iterate();
}
mat.display();
}