fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. //Mayar Mahmoud Mabrouk
  6. {
  7. int i,j,n;
  8. int a[5][5];
  9. cout <<endl<<"enter the dimensions:";
  10. cin>>n;
  11. cout<<endl<<"enter matrix elements > ";
  12. for(i=0;i<n;i++)
  13. for(j=0;j<n;j++)
  14. cin>>a[i][j];
  15. for(j=0; j < n; j++)
  16. {
  17. i=0;
  18. a[i][j] = a[i][j];
  19. }
  20.  
  21.  
  22. for(j=0; j < n; j++)
  23.  
  24. a[1][j]= a[1][j]-(a[0][j]*(a[1][0] / a[0][0]));
  25.  
  26. for(j=0; j < n; j++)
  27.  
  28. a[2][j]= a[2][j]-(a[0][j]*(-a[2][0] / a[0][0]));
  29.  
  30. for(j=0; j < n; j++)
  31. a[2][j]=a[2][j]-(a[1][j]*(-a[2][1]/a[1][1]));
  32.  
  33. cout << "triangular matrix" << endl;
  34. for (i=0; i <= n; i++)
  35. {
  36. for (j=0; j <= n; j++)
  37. cout << a[i][j] <<" ";
  38. cout << endl;
  39.  
  40. }
  41.  
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 3460KB
stdin
3
4 4 3 
2 8 9 
1 6 4 
stdout
enter the dimensions:
enter  matrix elements > triangular matrix
4    4    3    2    
2    8    9    -1216970720    
1    6    4    134517028    
134514496    134517424    134517092    134515730