diff --git a/CPP/Top_2_Maximum_number_in_Array.cpp b/CPP/Top_2_Maximum_number_in_Array.cpp new file mode 100644 index 0000000..67be8ed --- /dev/null +++ b/CPP/Top_2_Maximum_number_in_Array.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; +void maxAndSecondMax(int *arr, int size){ + int max= INT_MIN; + int s_max= INT_MIN; + for(int i=0;imax){ + s_max= max; + max= arr[i]; + } + else if(arr[i]> s_max && arr[i]!= max){ + s_max= arr[i]; + } + } + if(s_max==INT_MIN){ + s_max= -1; + } + cout<<"1st max is "<>n; + int *arr=new int[n]; + cout<<"enter numbers "<>arr[i]; + } + maxAndSecondMax(arr,n); + delete [] arr; + arr=0; + return 0; +} \ No newline at end of file