Advertisement
MSlomiany

cztery_macierze_iloczyn_wektorowy_14_05_2018[FUN]

May 14th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. // cztery_macierze_14_05_2018.cpp: Określa punkt wejścia dla aplikacji konsoli.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <string>
  8. using namespace std;
  9. typedef long double ld;
  10. const int W = 10;
  11. const int K = 10;
  12.  
  13. void wczytaj(int m, int n, ld w1[][K], string name)
  14. {
  15.     int i, j;
  16.     cout << "Podaj elementy macierzy " << name << endl;
  17.     for (i = 0; i < m; i++)
  18.     {
  19.         for (j = 0; j < n; j++)
  20.         {
  21.             cout << name << "[" << i + 1 << "][" << j + 1 << "]: ";
  22.             cin >> w1[i][j];
  23.         }
  24.     }
  25. }
  26.  
  27. void wypisz(int m, int n, ld w1[][K], string name)
  28. {
  29.     int i, j;
  30.     cout << "Macierz " << name << ": " << endl;
  31.     for (i = 0; i < m; i++)
  32.     {
  33.         for (j = 0; j < n; j++)
  34.         {
  35.             cout << fixed << setw(10) << setprecision(3) << w1[i][j] << " ";
  36.         }
  37.         cout << "\n";
  38.     }
  39. }
  40.  
  41. void KUBA(int m, int n, ld w1[][K], ld w2[][K], ld w3[][K], int GRZEGORZ)
  42. {
  43.     for (int i = 0; i < m; i++)
  44.     {
  45.         for (int j = 0; j < n; j++)
  46.         {
  47.             w3[i][j] = w1[i][j] + GRZEGORZ*w2[i][j];
  48.         }
  49.     }
  50. }
  51.  
  52. void MICHAŁ(int m, int n, ld w1[][K], ld w2[][K], ld w3[][K], string name1, string name2)
  53. {
  54.     for (int i = 0; i < m; i++)
  55.     {
  56.         for (int j = 0; j < n; j++)
  57.         {
  58.             w3[i][j] = 0;
  59.             for (int k = 0; k < n; k++)
  60.             {
  61.                 w3[i][j] += w1[i][k] * w2[k][j];
  62.             }
  63.         }
  64.     }
  65. }
  66.  
  67.  
  68. int _tmain(int argc, _TCHAR* argv[])
  69. {
  70.     setlocale(LC_ALL, "");
  71.     ld A[10][10];
  72.     string namea = "A";
  73.     ld B[10][10];
  74.     string nameb = "B";
  75.     ld C[10][10];
  76.     string namec = "C";
  77.     ld D[10][10];
  78.     string named = "D";
  79.     ld E[10][10];
  80.     string namee = "E";
  81.     ld POM1[10][10];
  82.     ld POM2[10][10];
  83.     int m, n, p, i, j, MARCIN;
  84.     //deifniowanie ilości elementów
  85.     cout << "Podaj ilość wierszy macierzy " << namea << "(max. 10)" << endl;
  86.     do {
  87.         cin >> m;
  88.     } while (m <= 0 || m > 10);
  89.     cout << "Podaj ilość kolumn macierzy" << namea << "(max. 10)" << endl;
  90.     do {
  91.         cin >> n;
  92.     } while (n <= 0 || n > 10);
  93.     cout << "Podaj ilość kolumn macierzy" << nameb << "(max. 10)" << endl;
  94.     do {
  95.         cin >> p;
  96.     } while (p <= 0 || p > 10);
  97.     //wczytywanie elementów
  98.     wczytaj(m, n, A, namea);
  99.     wczytaj(n, p, B, nameb);
  100.     wczytaj(m, p, C, namec);
  101.     wczytaj(m, p, D, nameb);
  102.     //wypisywanie macierzy
  103.     wypisz(m, n, A, namea);
  104.     wypisz(n, p, B, nameb);
  105.     wypisz(m, p, C, namec);
  106.     wypisz(m, p, D, nameb);
  107.     //iloczyn wektorowy
  108.     MICHAŁ(m, p, A, B, POM1, namea, nameb);
  109.     //odejmowanie
  110.     MARCIN = -1;
  111.     KUBA(m, p, POM1, D, POM2, MARCIN);
  112.     //dodawanie
  113.     MARCIN = 1;
  114.     KUBA(m, p, POM2, C, E, MARCIN);
  115.     //wypisywanie wyniku
  116.     wypisz(m, p, E, namee);
  117.     system("PAUSE");
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement