Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- //---------------------------------------------------------------------------
- using namespace std;
- int main(int argc, char* argv[])
- {
- int sam;
- int W;
- cout << "Jeśli chcesz samemu podawać liczby do macierzy wybierz 0, jeśli chcesz żeby liczby pojawiły się losowo wybierz 1" << endl;
- cin>>sam;
- cout << "podaj rozmiar macierzy ";
- cin >> W;
- float **Tab;
- float **t;
- int i, j, k;
- Tab = new float *[W];
- t = new float*[W];
- for (j = 0; j<W; j++)Tab[j] = new float[j];
- for (j = 0; j<W; j++)t[j] = new float[j];
- if(sam==1){
- cout << "macierz pierwotna to \n\n";
- for (i = 0; i<W; ++i)
- {
- for (j = 0; j<W; ++j)
- {
- Tab[i][j] = rand() % 10;
- cout << Tab[i][j] << " ";
- }
- cout << "\n";
- }
- }
- if(sam==0){
- for(int i = 0 ; i<W ; i++)
- {
- for(int j = 0 ; j<W ; j++)
- {
- cout<<"Podaj liczbe która bedzie w wierszu "<< i<< " Oraz kolumnie "<<j<< endl; ;
- cin>>Tab[i][j];
- }
- cout<<"\n\n";
- }
- cout << "macierz pierwotna to \n\n";
- for (int i = 0; i<W; ++i)
- {
- for (int j = 0; j<W; ++j)
- {
- cout << Tab[i][j] << " ";
- }
- cout << "\n";
- }
- }
- for (int i = 0; i<W; i++)
- {
- Tab[i][i] = 1 / Tab[i][i];
- for (j = 0; j<W; j++) if (j != i)
- {
- Tab[j][i] = Tab[j][i] * Tab[i][i];
- for (k = 0; k<W; k++) if (k != i)
- {
- Tab[j][k] -= Tab[j][i] * Tab[i][k];
- if (j == (W - 1))
- Tab[i][k] = -(Tab[i][k] * Tab[i][i]);
- }
- }
- }
- cout << "\nmacierz odwrotna\n\n";
- int w = W - 1;
- for (j = 0; j<w; j++) Tab[w][j] = -(Tab[w][j] * Tab[w][w]);
- for (int i = 0; i<W; i++)
- {
- for (j = 0; j<W; j++)
- {
- cout.width(10);
- cout << Tab[i][j] << " ";
- }
- cout << endl;
- }
- cout << "\n PRESS ENTER";
- cin.sync();
- cin.get();
- for ( int i = 0; i<W; ++i)
- {
- delete[] Tab[i];
- delete[] t;
- }
- delete[] Tab;
- delete[] t;
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement