Write a program to create a dynamic array of user defined size. Size should be in the range of 0 to 15. Write a function FindLarge that should ask user to enter a non-negative number. Function should find the next largest number than the input number in the list.
#include <iostream>
using namespace std;
int FindLarge(int array[], int size){
    int x; 
    do{
        cout<<"Enter a non-negative number: ";
        cin>>x;
    }while(x < 0);
    int largest = x;
    for(int i = 0; i < size; i++){
        if(array[i] > x){
            largest = array[i];
            return largest;
        }
    }
    return largest + 1;
}
int main(){
    int size;
    do{
    cout<<"Enter size of array (between 0 and 15): ";
    cin>>size;
    }while(size > 15 || size < 0);
    int *array;
    array = new int[size];
    cout<<"Input items in the array: \n";
    for(int i = 0; i < size; i++){
        cin>>array[i];
    }
    int large = FindLarge(array, size);
    cout<<"Next largest number than the input number is: "<<large<<endl;
    return 0;
}
Comments