Question: C++ USE BASIC CODING: NO FUNCTIONS, NO EQUATIONS, JUST BASIC IF ELSE OR FOR LOOPS. Write a program to find a peak in an array

C++ USE BASIC CODING: NO FUNCTIONS, NO EQUATIONS, JUST BASIC IF ELSE OR FOR LOOPS.

C++ USE BASIC CODING: NO FUNCTIONS, NO EQUATIONS, JUST BASIC IF ELSE

Write a program to find a peak in an array of ints. Suppose the array is f-1, 0, 2, 5, 6, 8,7]. The output should be "A peak is at array index 5 and the value is 8." This is because the value 8 is larger than its predecessor 6 and its successor 7 in the given array. Note that 8 occurs at index 5. (The array starts at index 0.) A number at index i in an array X is considered a peak if: X[i]>-X[i-1] and X[j> X[i+1]. If i is at the beginning of the array, then peak is if X[i]>-X[i+1]. If i is at end of array, then peak is if X[i]>-X[i-1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!