BlackWolfy

Calculating the area of 'n' right-angled triangles and finding the largest one

Feb 10th, 2023
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int index=0;
  6.     int max=0;
  7.     int n;
  8.     cout << "How many right-angled triangles do you wish to calculate: "<<endl;
  9.     cin >> n;
  10.    int* a = new int[n];
  11.    int* b = new int[n];
  12.    int* s = new int[n];
  13.     for (int i = 0; i < n; i++) { //loop for entering information about the triangle and calculating the area
  14.         cout << "Enter cathetus a for triangle number: " << i + 1<<endl;
  15.         cin >> a[i];
  16.         cout << "Enter cathetus b for triangle number: " << i + 1<<endl;
  17.         cin >> b[i];
  18.         s[i] = (a[i] * b[i]) / 2;
  19.     }
  20.     for (int i = 0; i < n; i++) { //loop finding the largest area of a triangle
  21.         if (s[i] > max) {
  22.             max = s[i];
  23.             index = i;
  24.         }
  25.     }
  26.     cout << "Triangle number "<<index+1<<" has the biggest area of "<<max<<" square centimeters!";
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment