diff --git a/C++/Second Largest Element in Array.cpp b/C++/Second Largest Element in Array.cpp new file mode 100644 index 0000000..9f00161 --- /dev/null +++ b/C++/Second Largest Element in Array.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + +int second_Largest(int *arr, int n) +{ + int sec=-1,largest=0; + for(int i=0;iarr[largest]) + { + sec=largest; + largest=i; + } + else if (arr[i]arr[sec] ) + { + sec=i; + } + } + } + return arr[sec]; +} + +int main() +{ + int n; + cout<<"Enter the size : "; + cin>>n; + int arr[n]; + cout<<"Enter the elements: "; + for(int i=0;i>arr[i]; + } + int ans=second_Largest(arr,n); + cout<<"The second largest element is :"<