-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gauss Jordan.cpp
51 lines (47 loc) · 1.16 KB
/
Gauss Jordan.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cout << "Enter number of variable:"; //asking for no of simultaneous eqn
cin >> n;
float A[n][n+1], X[n], temp;
//input system
cout << "enter coeff of eqn:" << endl;
for(int i = 0; i < n ; i++)
for(int j = 0; j < (n+1) ; j++)
cin >> A[i][j];
//column action
for(int j = 0; j <n ; j++)
{
//row acion
for(int i = 0; i < n ;i++)
{
if(i != j)
{
temp = A[i][j]/A[j][j]; //neccessary otherwise previous value=0
// for shifting in column during substraction
for(int k = 0; k < (n+1) ; k++)
{
A[i][k] = A[i][k] - temp*A[j][k];
}
}
}
}
cout<<"matrix is:"<<endl;
for(int i=0; i<n; i++)
{
for(int j=0; j<n+1; j++)
{
cout<<A[i][j]<<" \t ";
}
cout<<endl;
}
cout << "soln=";
for(int i = 0; i< n; i++)
{
X[i] = A[i][n]/A[i][i];
cout << X[i] << ",";
}
}