Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- float a[4][5], b[4], x[4];
- int i,j,n;
- cout << "Enter number of variables: ";
- cin>>n;
- cout << "Enter the co-efficients: " << endl;
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n+1; j++)
- {
- cin>>a[i][j];
- }
- }
- for(i=1; i<4; i++)
- {
- x[i] = 0;
- }
- for (i=1; i<=15; i++){
- x[1] = (a[1][4] - (a[1][2]*x[2] + a[1][3]*x[3])) / a[1][1];
- x[2] = (a[2][4] - (a[2][1]*x[1] + a[2][3]*x[3])) / a[2][2];
- x[3] = (a[3][4] - (a[3][1]*x[1] + a[3][2]*x[2])) / a[3][3];
- cout <<"Iteration : "<<i<<" "<<endl
- << "x : " << x[1] << " ; y : " << x[2] << " ; z : " << x[3] <<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement