Advertisement
AlexandruFilipescu

C++ Get the area of the largest rectangle by using struct and an 2D array

Jul 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct dreptunghi {
  5.     int Ax;
  6.     int Ay;
  7.     int Bx;
  8.     int By;
  9.     int Aria;
  10. };
  11.  
  12. int main() {
  13.     int matrice[4][4],i,j;
  14.     dreptunghi dreptunghi[4];
  15.     int k = 0;
  16.     int max = INT_MIN;
  17.     int dreptunghiul_max;
  18.  
  19.     for (i = 0; i < 2*2; i++) {
  20.         for (j = 0; j < 2*2;j++) {
  21.             if(j<=1){
  22.                 if (j % 2 == 0) {
  23.                     cout << "Dati punctul Ax "; cin >> dreptunghi[k].Ax;
  24.                     matrice[i][j] = dreptunghi[k].Ax;
  25.                 } else {
  26.                     cout << "Dati punctul Ay "; cin >> dreptunghi[k].Ay;
  27.                     matrice[i][j] = dreptunghi[k].Ay;
  28.                   }
  29.                 } else {
  30.                     if (j % 2 == 0) {
  31.                         cout << "Dati punctul Bx "; cin >> dreptunghi[k].Bx;
  32.                         matrice[i][j] = dreptunghi[k].Bx;
  33.                     }
  34.                     else {
  35.                         cout << "Dati punctul By "; cin >> dreptunghi[k].By;
  36.                         matrice[i][j] = dreptunghi[k].By;
  37.                     }
  38.             }
  39.         }
  40.         dreptunghi[k].Aria = (dreptunghi[k].Bx - dreptunghi[k].Ax) * (dreptunghi[k].Ay - dreptunghi[k].By);
  41.         k++;
  42.         cout << endl;
  43.     }
  44.  
  45.     for (i = 0; i < 4; i++) {
  46.         if (dreptunghi[i].Aria > max) {
  47.             max = dreptunghi[i].Aria;
  48.             dreptunghiul_max = i+1;
  49.         }
  50.     }
  51.  
  52.     cout << "Dreptunghiul cel mai mare are aria: " << max << " Si este cel cu numarul: " << dreptunghiul_max;
  53.  
  54.     system("pause");
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement