Posts

Showing posts with the label C array programming

Binary Searching: Find last occurrence of element in array

Simple C program to find last occurrence index of an element in sorted array. For example if array is {34,45,45,45,56,57,57,68,78,78,78,78} then last occurrence of element 45 is at index 3 and last occurrence of element 78 is at index 11.

Binary Search: Search an element in sorted array

C program for binary search: Binary search works only in sorted array. Prerequisite of binary search is that array should be sorted. If you want to implement binary search in unsorted array then you should sort array using any sorting algorithm like merge sort, quick sort etc and then implement binary search.

Find out second largest element in array C program

Find second largest element in given array. For example if arr is {2,6,3,12,7,9,4} then second largest element is 9 . Our task is find out this element.