daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Jan 20th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int maxNum(int[], int);
  6. int nextMaxNum(int[], int, int);
  7. int maxNumIndex;
  8.  
  9. int main(){
  10.     int n;
  11.     int* array = NULL;
  12.     cin >> n;
  13.     array = new int [n];
  14.     for (int i = 0; i < n; i++)
  15.         cin >> array[i];
  16.     cout << maxNum(array, n) << endl;
  17.     cout << nextMaxNum(array, n, maxNumIndex) << endl;
  18.     int a = maxNum(array, n);
  19.     int b = nextMaxNum(array, n, maxNumIndex);
  20.     cout << a*b << endl;
  21.     return 0;
  22. }
  23.  
  24. int maxNum (int array[], int size){
  25.     int max = array[0];
  26.     for (int i = 0; i < size; i++){
  27.         if (array[i] > max){
  28.             max = array[i];
  29.             maxNumIndex = i;
  30.         }
  31.         else continue;
  32.     }
  33.     return max;
  34. }
  35.  
  36. int nextMaxNum(int array[], int size, int comparedIndex){
  37.     int index = 0;
  38.     int max = array[index];
  39.     if (index == comparedIndex)
  40.         max = array[index+1];
  41.     for (int i = 0; i < size; i++){
  42.         if (array[i] > max){
  43.             if (i != comparedIndex)
  44.                 max = array[i];
  45.         }
  46.         else continue;
  47.     }
  48.     return max;
  49. }
RAW Paste Data
Top