C Exercises: Find the index of first peak element in a given array
97. Index of First Peak Element
Write a program in C to find the index of the first peak element in a given array.
Expected Output:
The given array is:
5 12 13 20 16 19 11 7 25
The index of first peak element in the array is: 3
The task is to write a C program that finds the index of the first peak element in a given array. A peak element is defined as an element that is greater than its neighbors. The program should traverse the array, identify the first occurrence of such an element, and display its index.
Sample Solution:
C Code:
Output:
The given array is: 5 12 13 20 16 19 11 7 25 The index of first peak element in the array is: 3
Visual Presentation:
Flowchart:/p>
For more Practice: Solve these Related Problems:
- Write a C program to find the first peak element in an array by comparing each element with its neighbors.
- Write a C program to identify the index of the first peak using a binary search approach in a unimodal array.
- Write a C program to determine the first peak element recursively.
- Write a C program to find the first peak and then output both the peak value and its index.
C Programming Code Editor:
Previous: Write a program in C to segregate even and odd elements on an array.
Next: Write a program in C to return the largest span found in the leftmost and rightmost appearances of same value(values are inclusive) in a given array.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.