Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. double Arr[50][50] , x[50], err[3] = {.001 , .05 , .005};
  5. int n;
  6.  
  7. void seidal(){
  8. int i, j, flag =0;
  9. double temp;
  10. cout<<"n\tx1 E of x1 \t x2 E of x2 \t x3 E of x3\n";
  11. do{
  12. // flag = 1;
  13. for(i=0; i<n; i++){
  14. temp = x[i];
  15. x[i] = Arr[i][n];
  16. for(j=0; j<n; j++){
  17. if(i != j)
  18. x[i] -= (Arr[i][j] * x[j]);
  19. }
  20. x[i] /= Arr[i][i];
  21. if( fabs(x[i] - temp) < err[i] )
  22. flag++;
  23. cout<<i<<setprecision(4)<<"\t\t"<<x[i]<<"\t\t"<<x[i+1]<<"\t\t "<<x[i+2]<<endl;
  24. }
  25. }while(flag<n);
  26.  
  27.  
  28. cout<<i<<setprecision(4)<<"\t\t"<<x[0]<<"\t\t"<<x[1]<<"\t\t "<<x[2]<<endl;
  29.  
  30. }
  31.  
  32.  
  33. int main(){
  34. freopen("input.txt","r",stdin);
  35. int i,j;
  36. //cout<<"Enter the row number :";
  37. cin>>n;
  38. //cout<<"Enter the co-efficient of x :";
  39. for(i=0; i<n; i++){
  40. for(j=0; j<=n; j++){
  41. cin>>Arr[i][j];
  42. }
  43. }
  44.  
  45. //cout<<"Enter the guesses value :";
  46. for(i=0; i<n; i++)
  47. cin>>x[i];
  48.  
  49. seidal();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement