Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cztery_macierze_14_05_2018.cpp: Określa punkt wejścia dla aplikacji konsoli.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- typedef long double ld;
- const int W = 10;
- const int K = 10;
- void wczytaj(int m, int n, ld w1[][K], string name)
- {
- int i, j;
- cout << "Podaj elementy macierzy " << name << endl;
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- cout << name << "[" << i + 1 << "][" << j + 1 << "]: ";
- cin >> w1[i][j];
- }
- }
- }
- void wypisz(int m, int n, ld w1[][K], string name)
- {
- int i, j;
- cout << "Macierz " << name << ": " << endl;
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- cout << fixed << setw(10) << setprecision(3) << w1[i][j] << " ";
- }
- cout << "\n";
- }
- }
- void KUBA(int m, int n, ld w1[][K], ld w2[][K], ld w3[][K], int GRZEGORZ)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- w3[i][j] = w1[i][j] + GRZEGORZ*w2[i][j];
- }
- }
- }
- void MICHAŁ(int m, int n, ld w1[][K], ld w2[][K], ld w3[][K], string name1, string name2)
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- w3[i][j] = 0;
- for (int k = 0; k < n; k++)
- {
- w3[i][j] += w1[i][k] * w2[k][j];
- }
- }
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "");
- ld A[10][10];
- string namea = "A";
- ld B[10][10];
- string nameb = "B";
- ld C[10][10];
- string namec = "C";
- ld D[10][10];
- string named = "D";
- ld E[10][10];
- string namee = "E";
- ld POM1[10][10];
- ld POM2[10][10];
- int m, n, p, i, j, MARCIN;
- //deifniowanie ilości elementów
- cout << "Podaj ilość wierszy macierzy " << namea << "(max. 10)" << endl;
- do {
- cin >> m;
- } while (m <= 0 || m > 10);
- cout << "Podaj ilość kolumn macierzy" << namea << "(max. 10)" << endl;
- do {
- cin >> n;
- } while (n <= 0 || n > 10);
- cout << "Podaj ilość kolumn macierzy" << nameb << "(max. 10)" << endl;
- do {
- cin >> p;
- } while (p <= 0 || p > 10);
- //wczytywanie elementów
- wczytaj(m, n, A, namea);
- wczytaj(n, p, B, nameb);
- wczytaj(m, p, C, namec);
- wczytaj(m, p, D, nameb);
- //wypisywanie macierzy
- wypisz(m, n, A, namea);
- wypisz(n, p, B, nameb);
- wypisz(m, p, C, namec);
- wypisz(m, p, D, nameb);
- //iloczyn wektorowy
- MICHAŁ(m, p, A, B, POM1, namea, nameb);
- //odejmowanie
- MARCIN = -1;
- KUBA(m, p, POM1, D, POM2, MARCIN);
- //dodawanie
- MARCIN = 1;
- KUBA(m, p, POM2, C, E, MARCIN);
- //wypisywanie wyniku
- wypisz(m, p, E, namee);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement