Advertisement
Felanpro

Finding biggest sum between two equally long arrays

Mar 9th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int arr_one[4] = {4, 8, 1, 3};
  8.     int arr_two[4] = {9, 0, 3, 1};
  9.     int arr_sum[4 + 4 + 4 + 4];
  10.     int loops = 0;
  11.  
  12.     for (int y = 0; y < 4; y++)
  13.     {
  14.         for (int x = 0; x < 4; x++)
  15.         {
  16.             arr_sum[loops] = arr_one[y] + arr_two[x];
  17.             loops++;
  18.         }
  19.     }
  20.     //int pause; cin >> pause;
  21.  
  22.     //Gnome sort the arr_sum array!
  23.  
  24.     int p = 0;
  25.     int temp;
  26.  
  27.     while (p < 16)
  28.     {
  29.         if (p == 0 || arr_sum[p] >= arr_sum[p - 1])
  30.         {
  31.             p++;
  32.         }
  33.         else
  34.         {
  35.             temp = arr_sum[p - 1];
  36.             arr_sum[p - 1] = arr_sum[p];
  37.             arr_sum[p] = temp;
  38.             p--;
  39.         }
  40.     }
  41.  
  42.     cout << arr_sum[14];
  43.  
  44.     int pp;
  45.     cin >> pp;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement