answer.
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]
1 year 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]1 year 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
Brian drives a car that uses voice commands for navigation. Which field did researchers use to develop a car-based AI that under
pickupchik [31]

Answer:

A, Computer Engineering

4 0
2 years ago
Writing a program in a language such as c or java is known as _____ the program.
Angelina_Jolie [31]
<span>Writing a program in a language such as c or java is known as coding the program</span>
8 0
2 years ago
The properly marked source document states: (C) Operation Panda will take place on 29 September. The new document states: (C) On
skelet666 [1.2K]

Answer:

The answer is "Contained in"

Explanation:

Its term refers to the classified information of the extraction process, even though outlined in an authorized categorization instruction origin without extra explanation or review, and incorporates these data in a new document.

In this concept, the information appears in the extracted word-for-word, its definition of 'in' will apply, or if its data has been paraphrased or restated from the current text, that's why we can say that this concept derivatively classifies the statement in new documents.

4 0
1 year ago
Write code which takes a sentence as an input from the user and then prints the length of the first word in that sentence.
Afina-wow [57]

import java.util.Scanner;

public class U2_L3_Activity_Four {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a sentence.");

       String sent = scan.nextLine();

       int count = 0;

       for (int i = 0; i < sent.length(); i++){

           char c = sent.charAt(i);

           if (c != ' '){

               count++;

       }

           else{

               break;

           }

       

   }

       System.out.println("The first word is " + count +" letters long");

   

   }

}

We check to see when the first space occurs in our string and we add one to our count variable for every letter before that. I hope this helps!

7 0
1 year ago
Which of the following are true statements about digital certificates in Web browsers?I. Digital certificates are used to verify
vladimir2022 [97]

Answer:

I only

Explanation:

Digital certificate are virtual encrypted keys or password used by individuals or organization  as a means of establishing secure connections between servers and websites so as to  be able to authenticate that only the legitimate people are having access to the information.

6 0
1 year ago
Other questions:
  • A circuit contains three resistors connected in parallel. The value of R1 is 2 K , the value or R2 is 6 K , and the value of R3
    5·1 answer
  • When a typeface does not have any extra embellishments on the top and bottom of the letterforms, it is called a ________ font?
    12·1 answer
  • Julie is working on a spreadsheet with data about the company's profits. They will be sharing this data with customers. She chec
    6·2 answers
  • Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation
    6·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    5·1 answer
  • A news channel runs a two-minute story on phishing scams. The report features the testimonies of a phishing victim and a compute
    7·1 answer
  • Translate the following MIPS code to C. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3
    8·1 answer
  • Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences
    7·1 answer
  • Calvin is an aspiring graphic designer. He wants to achieve Adobe Certified Expert certification in software that will be helpfu
    9·1 answer
  • What is the average number of nodes accessed in search for a particular element in an unordered list? In an ordered list? In an
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!