Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     srand( time( NULL ) );
  9.     double det;
  10.     int n,sam;
  11.      bool wh= true;
  12.     cout << "Jeoli chcesz samemu podawaa liczby do macierzy wybierz 0, jeoli chcesz ?eby liczby pojawi3y sie losowo wybierz 1" << endl;
  13.     cin>>sam;
  14.     cout << "Podaj poziom tablicy (liczbe wierszy oraz kolumn)" << endl;
  15.     cin >>n;
  16.     double tab_A[n][n];
  17.      det=tab_A[0][0];
  18.     if(sam==1){
  19.     for(int i = 0 ; i<n ; i++)
  20.     {
  21.         for(int j = 0 ; j<n ; j++)
  22.         {
  23.             tab_A[i][j]=rand()%10;
  24.             cout<<tab_A[i][j]<< " " ;
  25.  
  26.         }
  27.         cout<<"\n\n";
  28.     }
  29.     }
  30.     if(sam==0){
  31. for(int i = 0 ; i<n ; i++)
  32.     {
  33.         for(int j = 0 ; j<n ; j++)
  34.         {
  35.             cout<<"Podaj liczbe która bedzie w wierszu "<< i<<  " Oraz kolumnie "<<j<< endl; ;
  36.             cin>>tab_A[i][j];
  37.         }
  38.         cout<<"\n\n";
  39.     }}
  40.         det=tab_A[0][0];
  41.         for(int z=0; z<n-1; z++)
  42.         {
  43.             for(int i=z+1; i<n; i++)
  44.             {
  45.                 for(int j=z+1;j<n;j++)
  46.                 {
  47.                    tab_A[i][j]=tab_A[i][j]-(tab_A[i][z]/tab_A[z][z])*tab_A[z][j];
  48.                 }
  49.             }
  50.             det=det*tab_A[z+1][z+1];
  51.  
  52.         }
  53.     cout << "Wyznacznik wynosi " << det << endl;
  54.  
  55.   system("pause");
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement