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
topjm [15]
3 years ago
14

Write a function named firstLast2 that takes as input an array of integers and an integer that specifies how many entries are in

the array. The function should return true if the array starts or ends with the digit 2. Otherwise it should return false. Test your function with arrays of different length and with the digit 2 at the beginning of the array, end of the array, middle of the array, and missing from the array.
Computers and Technology
1 answer:
frosja888 [35]3 years ago
4 0

Answer:

<em>Written in C++</em>

#include<iostream>

using namespace std;

int firstLast2(int arr[], int n);

int main()

{

int n;

cout<<"Number of Elements: ";

cin>>n;  

int myarray[n];

for(int i = 0; i<n;i++) {

cin>>myarray[i];

}

firstLast2(myarray, n);

return 0;

}

int firstLast2(int arr[], int n){

if(arr[0] == 2 || arr[n - 1] == 2) {

 cout<<"True";

}

else {

cout<<"False";

}

}

Explanation:

<em>I've added the full source code as an attachment where I used comments to explain difficult lines</em>

Download cpp
You might be interested in
(Please select 2)
blondinia [14]
Choice selection depends on the type of learning each student has so one might work for one student but not another....
6 0
4 years ago
Necesito ejemplos de actitud filosófica por favor
GrogVix [38]

Answer:

La filosofía es una disciplina intelectual que estudia críticamente las cuestiones más básicas de la humanidad y la naturaleza. Preguntas fundamentales de la filosofía son, entre otras, las siguientes:

-¿Existe alguna realidad fuera de mis pensamientos?

-¿Qué es el conocimiento?

-¿Qué es la verdad?

-¿Qué hace que una acción sea valiosa?

-¿Los humanos y los animales tienen valor y son iguales o diferentes?

-¿Qué es el tiempo?

Así, el planteamiento y reflexión de este tipo de preguntas son claros ejemplos de actitud filosfófica.

7 0
3 years ago
In GamePoints' constructor, assign teamWhales with 500 and teamLions with 500. #include using namespace std; class GamePoints {
xxMikexx [17]

Answer:

Here is the GamePoints constructor:

GamePoints::GamePoints() :

/* Your code goes here */

{

teamLions = 500;

teamDolphins = 500;

}    

Explanation:

Here is the complete program:

#include  //to use input output functions

using namespace std; //to identify objects like cin cout

class GamePoints {  //class GamePoints

   public: GamePoints(); // constructor of GamePoints class

   void Start() const;  //method of GamePoints class

   private: //declare data members of GamePoints class

   int teamDolphins; // integer type private member variable of GamePoints

   int teamLions; }; // integer type private member variable of GamePoints

   GamePoints::GamePoints()  //constructor

    { teamLions = (500), teamDolphins= (500); }   //assigns 500 to the data members of teamLions  and teamDolphins of GamePoints class

   void GamePoints::Start() const    { //method Start of classs GamePoints

       cout << "Game started: Dolphins " << teamDolphins << " - " << teamLions << " Lions" << endl; }  //displays the values of teamDolphins and teamLions i.e. 500 assigned by the constructor

       int main() //start of main() function

       { GamePoints myGame;  // creates an object of GamePoints class

       myGame.Start(); //calls Start method of GamePoints class using the object

       return 0; }

The output of the program is:

Game started: Dolphins 500 - 500 Lions                    

8 0
3 years ago
Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code? String element = "red"; f
maksim [4K]

Answer:

The output of the given code as follows:

<u>Output: </u>

{"red", "green"}

Explanation:

  • In the given code a list is defined, which contains three elements, which are "red, red, and green". In the next step, a string variable "element" is initialized with a value that is "red".
  • Then a for loop is declared, that counts list size, and inside the loop and if block is declared, that compares the value list with element variable then it removes from the list.  

8 0
3 years ago
Will, there be any presents this year
garri49 [273]

Answer:

no why

Explanation:

8 0
3 years ago
Other questions:
  • A ________ is a small text file passed to a web browser on a user's computer by a web server.
    7·1 answer
  • A(n) ____ is a system designed to handle only very basic applications with an absolute minimum amount of hardware required by th
    9·1 answer
  • What's is the contribution of technology to the country?
    15·1 answer
  • There are types of templates​
    5·1 answer
  • Jim lost his job due to the replacement of robots in a manufacturing factory. As an ethical practice, what should the manufactur
    13·1 answer
  • Tyler is feeling overwhelmed by the programming assignment from his supervisor and wants to break the task down into smaller, mo
    5·2 answers
  • Complete the sentence.<br> In your program, you can open
    5·1 answer
  • What are the similarities characteristics between computer and human beings?​
    13·2 answers
  • Which of the following commands can be used to display socket information out to the terminal screen
    12·1 answer
  • A ____ attack is much more substantial than a dos attack because of the use of multiple systems to simultaneously attack a singl
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!