-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.GaussSeidal.cpp
More file actions
65 lines (56 loc) · 1.17 KB
/
10.GaussSeidal.cpp
File metadata and controls
65 lines (56 loc) · 1.17 KB
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
#include<bits/stdc++.h>
using namespace std;
double arr[100][100],x[100] = {0};
void GaussSeidal(int n, int t)
{
cout<<"iteration \t x[0] \t x[1] \t x[2]"<<endl;
for(int m = 1; m <= t; m++)
{
for(int i = 1; i<= n; i++)
{
double sum =0;
for(int j = 1; j<= n; j++)
{
if(i != j)
{
sum = sum + arr[i][j] * x[j];
}
}
sum = (arr[i][n+1] - sum);
sum = sum / arr[i][i];
x[i] = sum;
}
cout<<m<<"\t";
for(int i=1;i<=n;i++)
cout<<x[i]<<"\t";
cout<<endl;
}
}
void display(int n)
{
cout<<"Result : ";
for(int i = 1; i<= n; i++)
{
cout<<x[i]<<"\t";
}
}
int main()
{
int n,t,i,j;
freopen("in.txt","r",stdin);
cout<<"Enter the value of n :"<<endl;
cin>>n;
cout<<"Enter the Iteration No :"<<endl;
cin>>t;
cout<<"Enter the Equations "<<endl;
for(i = 1; i<=n; i++)
{
for(j = 1; j<=n+1; j++)
{
cin>>arr[i][j];
}
}
GaussSeidal(n,t);
display(n);
return 0;
}