1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lesya [120]
3 years ago
14

Write a program to find a peak in an array of ints. Suppose the array is {-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[i]>=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].

Computers and Technology
1 answer:
Sergeeva-Olga [200]3 years ago
5 0

Answer:

Following are the code to this question:

#include<iostream>//declaring header file  

using namespace std;

int main()//main method

{

int n= 6,j=0;//declaring integer variable

int X[n];//defining an array

for(j=0;j<=n;j++)//defining a loop for input value

cin>>X[j];//input value from the user

if(j==0) //defining if block that checks value at beginning

{

if(X[j]>=X[j+1])//defining if block to check to compare first and second value  

{

cout<<"A peak is at array index "<<j<<" and the value is "<<X[j];//use print method to largest value with index number  

}

}

else//defining else block

{

for(j=0;j<=n;j++)//defining for loop for compare other value

{

if(j==n-1) //use if block that checks next index  

{

if(X[j]>=X[j-1])//use if block to compare value  

cout<<"A peak is at array index "<<j<<" and the value is "<<X[j];//use print method to largest value with index number

}

else

{

if(X[j]>=X[j-1] && X[j]>=X[j+1])//comapre value

cout<<"A peak is at array index "<<j<<" and the value is "<<X[j];//use print method to largest value with index number

}

}

}

return 0;

}

Output:

please find the attached file.

Explanation:

In the given code, inside the main method two integer variable "n and j", is declared, in the next step, an array "x"is defined which input the value from the user end.

  • In the next step, multiple if block is used, in the first if block it comapre the first and second value if it grater then it will print the value with its index number.
  • In the next if block, it comapre is next value and if it grater then it will print the value with its index number.  

You might be interested in
Not a subject question but please help
Doss [256]

Answer:

You go to account settings, edit your profile and click preferences and then go to choose level and put which grade u are in the options r middle school, high school, and college

Explanation:

8 0
3 years ago
Read 2 more answers
In Microsoft Word, how would you change the amount of space that is put in after each paragraph?
lianna [129]
Right click the text you want to format, On the home tab click the line and paragraph spacing command . A drop down menu will appear. Move the mouse over the various options . The line spacing will change in the document. 

Was that helpful?
5 0
4 years ago
_ is the adherence to a personal code of principles.
trapecia [35]

Answer: Ethics

Explanation:

 Ethics is the basic principle for the personal code. The code of the ethics is basically designed for outline the values in the organization with honesty and integrity.

The ethics is basically depend upon the principle of core value of the organization. The code of the ethics basically guide the core value in the organization and breaking the rule of ethics can also cause termination from the organization.

Morality, integrity and honesty are all the sub part of the ethics vale in the organization. Therefore, ethics is the correct option.  

3 0
4 years ago
Which of these completes the sentence? People interpret information ___________. Choose one.
evablogger [386]

Explanation:

mannejaondpsbma0jdjdhdj

5 0
3 years ago
Read 2 more answers
Which expression adds 1 to the element of array arrayname at index i?
NemiM [27]
I believe the answer is <span>++arrayName[ i ].

</span>
8 0
3 years ago
Other questions:
  • A _________ provides multiple ports for connecting nodes and is aware of the exact address or identity of all the nodes attached
    15·2 answers
  • hard disk drive has 16 platters, 8192 cylinders, and 256 4KB sectors per track. The storage capacity of this disk drive is at mo
    13·1 answer
  • What is an LMS and how is it used?
    8·1 answer
  • Can someone help me
    8·1 answer
  • To build a framework for security policies and controls, one can use the following approach: 1) document the concepts and princi
    12·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • g Create a program that prompts a user to enter a login name and password. The correct login name is Admin, and the correct pass
    9·1 answer
  • Implement the above in c++, you will write a test program named create_and_test_hash.cc . Your programs should run from the term
    9·1 answer
  • What allows a programmer to write code quickly and efficiently for an action that must be repeated?
    14·1 answer
  • Let cell E2 = 100, what is the result of this formula? =NOT(E2&lt;100) *
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!