Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- double Arr[50][50] , x[50], err[3] = {.001 , .05 , .005};
- int n;
- void seidal(){
- int i, j, flag =0;
- double temp;
- cout<<"n\tx1 E of x1 \t x2 E of x2 \t x3 E of x3\n";
- do{
- // flag = 1;
- for(i=0; i<n; i++){
- temp = x[i];
- x[i] = Arr[i][n];
- for(j=0; j<n; j++){
- if(i != j)
- x[i] -= (Arr[i][j] * x[j]);
- }
- x[i] /= Arr[i][i];
- if( fabs(x[i] - temp) < err[i] )
- flag++;
- cout<<i<<setprecision(4)<<"\t\t"<<x[i]<<"\t\t"<<x[i+1]<<"\t\t "<<x[i+2]<<endl;
- }
- }while(flag<n);
- cout<<i<<setprecision(4)<<"\t\t"<<x[0]<<"\t\t"<<x[1]<<"\t\t "<<x[2]<<endl;
- }
- int main(){
- freopen("input.txt","r",stdin);
- int i,j;
- //cout<<"Enter the row number :";
- cin>>n;
- //cout<<"Enter the co-efficient of x :";
- for(i=0; i<n; i++){
- for(j=0; j<=n; j++){
- cin>>Arr[i][j];
- }
- }
- //cout<<"Enter the guesses value :";
- for(i=0; i<n; i++)
- cin>>x[i];
- seidal();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement