Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- int* localMax(int *arr, int size, int &localMaxSize)
- {
- int* localArray = new int[size];
- for(int i = 1; i < size - 1; i++)
- if((arr[i] > arr[i+1] && (arr[i]) > arr[i-1]))
- {
- localArray[localMaxSize] = arr[i];
- localMaxSize++;
- }
- return localArray;
- }
- int main()
- {
- const int SIZE = 10;
- int array[SIZE];
- int* localArray;
- int localMaxSize = 0;
- srand(time(NULL));
- for(int i = 0; i < SIZE; i++)
- array[i] = rand() % 10;
- for(int i = 0; i < SIZE; i++)
- cout << array[i] << " ";
- cout << endl;
- localArray = localMax(array, SIZE, localMaxSize);
- for(int i = 0; i < localMaxSize; i++)
- cout << localArray[i] << " ";
- delete localArray;
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment