nsnikolova1

Diagonal

May 18th, 2020
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. // Diagonal MATRICA ABOVE.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int size, rows, cols, input, tempNum, sum=0;
  11.     vector<vector<int>> Matrix;
  12.     cout << "Enter size of matrix: ";
  13.     cin >> size;
  14.     //preorameriavane na Matrix spiamo dannite
  15.     //row=col=size;
  16.     rows = cols = size;
  17.  
  18.    
  19.     //vuvejdane na danni
  20.     vector <int> InputRow;
  21.     for (int r = 0; r < rows; r++) //obikaliane redove
  22.     {
  23.         for (int c = 0; c < cols; c++) //ot 0 do broi koloni
  24.         {
  25.             cin >> input;
  26.             InputRow.push_back(input); //popylvene na danni vyv vectora za reda
  27.         }
  28.         Matrix.push_back(InputRow); //vmykvane na popylnenite danni ot reda
  29.         InputRow.clear();//Izchistvame reda
  30.     }
  31.     //print stoinosti Matrix
  32.     cout << "The MATRIX is: " << endl;
  33.     for (int r = 0; r < rows;r++) //obikaliane redove
  34.     {
  35.         for (int c = 0; c < cols; c++) //ot 0 do broi koloni
  36.         {
  37.             cout << Matrix[r][c] << " ";
  38.  
  39.         }
  40.         cout << endl;
  41.     }
  42.     //izchislenie suma ABOVE diagonal
  43.     //Row>Col
  44.     for (int r = 0; r < rows; ++r) //obikaliane redove
  45.     {
  46.         for (int c = 0; c < cols; c++) //ot 0 do broi koloni
  47.         {
  48.             if (r < c)
  49.             {
  50.  
  51.                 sum = sum + Matrix[r][c];
  52.             }
  53.  
  54.         }
  55.  
  56.     }
  57.     //pechat na sumata na elementite
  58.     cout << "Sum of numbers ?bove diagonal is: " << sum;
  59. }
  60.  
  61.  
  62. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  63. // Debug program: F5 or Debug > Start Debugging menu
  64.  
  65. // Tips for Getting Started:
  66. //   1. Use the Solution Explorer window to add/manage files
  67. //   2. Use the Team Explorer window to connect to source control
  68. //   3. Use the Output window to see build output and other messages
  69. //   4. Use the Error List window to view errors
  70. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  71. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment