From 710d7bfbf61d57ae84609f27a2964309b960f7e5 Mon Sep 17 00:00:00 2001 From: Prashant Bhapkar Date: Mon, 29 Aug 2022 20:39:31 +0530 Subject: [PATCH] Find Second largest element in the array --- algorithms/C/arrays/secondLargestElement.c | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 algorithms/C/arrays/secondLargestElement.c diff --git a/algorithms/C/arrays/secondLargestElement.c b/algorithms/C/arrays/secondLargestElement.c new file mode 100644 index 00000000..04263d26 --- /dev/null +++ b/algorithms/C/arrays/secondLargestElement.c @@ -0,0 +1,30 @@ +//Second largest element in the array + +#include +#include + +int second(int arr[],int size) +{ + int max1=arr[0],max2; + for(int i=0;imax1) //Find largest element in the array + { + max2=max1; + max1=arr[i]; + } + else if (arr[i]>max2 && arr[i]