Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <iomanip>
- //Andrzej Porebski gr2 imim
- //dzialania na macierzach
- using namespace std;
- float tab [3][3];
- void suma()
- {
- float k = tab[0][0] + tab [1][1] + tab [2][2];
- cout << k << endl;
- }
- void iloczynskalar()
- {
- cout << "iloczyn macierzy przez skalar ma postac: " << endl << endl;
- for (int g = 0; g <= 3; g++)
- {
- for (int h = 0; h <= 3; h++)
- {
- float l = tab[g][h] * skalar;
- cout << setw(5) << l;
- }
- cout << endl;
- }
- }
- void iloczynsama()
- {
- float w = tab[0][0]
- cout << "iloczyn macierzy przez sama siebie wynosi: " << endl << endl;
- for (int x = 0; x <= 3; x++)
- {
- for (int y = 0; y <= 3; y++)
- {
- float iloczynxyz[x][y] = 0;
- for (int z = 0; z <= 3; z++)
- {
- iloczynxyz[x][y] += tab[x][y] * tab[x][y];
- }
- cout << setw(5) << iloczynxyz[x][y];
- }
- cout << endl;
- }
- }
- int main()
- {
- fstream dane ("plik.txt", ios::in);
- float skalar;
- cout << "Podaj liczbe do iloczynu: ";
- cin >> skalar;
- if (dane.good() == false)
- {
- cout << "problem z plikiem!" << endl;
- exit (0);
- }
- else
- {
- cout << "wczytana macierz ma postac: " << endl << endl;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- dane >> tab[i][j];
- cout << setw(5)<< tab [i][j];
- }
- cout << endl << endl;
- }
- }
- dane.close();
- cout << "suma na diagonali wynosi: ";
- suma();
- iloczynskalar();
- iloczynsama();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement