Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int maxNum(int[], int);
- int nextMaxNum(int[], int, int);
- int maxNumIndex;
- int main(){
- int n;
- int* array = NULL;
- cin >> n;
- array = new int [n];
- for (int i = 0; i < n; i++)
- cin >> array[i];
- cout << maxNum(array, n) << endl;
- cout << nextMaxNum(array, n, maxNumIndex) << endl;
- int a = maxNum(array, n);
- int b = nextMaxNum(array, n, maxNumIndex);
- cout << a*b << endl;
- return 0;
- }
- int maxNum (int array[], int size){
- int max = array[0];
- for (int i = 0; i < size; i++){
- if (array[i] > max){
- max = array[i];
- maxNumIndex = i;
- }
- else continue;
- }
- return max;
- }
- int nextMaxNum(int array[], int size, int comparedIndex){
- int index = 0;
- int max = array[index];
- if (index == comparedIndex)
- max = array[index+1];
- for (int i = 0; i < size; i++){
- if (array[i] > max){
- if (i != comparedIndex)
- max = array[i];
- }
- else continue;
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement