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
I’m so lost. which username do i do.
koban [17]

Answer:

the username you feel like using

5 0
2 years ago
Read 2 more answers
computer hardware without software is useless while computer software without hardware is meaningless. explain what do you under
Rainbow [258]

Answer:

That the software is useless

Explanation:

6 0
3 years ago
why might a portrait be both a portrait of the subject and the photographer? how is a photographer present in a portrait?
Nataliya [291]
Because of the reflection on the window or mirror.
5 0
2 years ago
Read 2 more answers
In what way can a costume be deleted ?
alex41 [277]

Answer:

Clicking the "X" button towards the upper-right of each costume's icon in the Costume Pane will delete

Explanation:

5 0
2 years ago
Create a test that prompts a user to enter a 5-digit PIN in the main procedure and then calls Validate PIN procedure to validate
Pie

Answer:

See explaination

Explanation:

#include <iomanip>

#include <string>

#include <fstream>

using namespace std;

void getName(string);

void getPin(int,int);

void displayMenu(int);

string name;

int pin1, pin2, ch ;

int main()

{

cout << fixed << showpoint << setprecision(2);

getName(name);

getPin(pin1,pin2);

displayMenu(ch );

system("pause");

}

void getName(string name)

{

cout << "Enter your name: ";

cin >> name;

if (name = "AXBY") || (name != "ABGSHY"))

{

getName(name);

}

}

void getPin(int pin1, int pin2)

{

string name;

if (name == "AXBY")

{

cout << "Please Enter Pin: ";

cin >> pin1;

if (pin1 != 4433)

{

cout << "Pin incorrect please try again!";

cin >> pin1;

}

}

if (name == "ABGSHY")

{

cout << "Please Enter Pin: ";

cin >> pin2;

if (pin2 != 2849)

{

cout << "Pin incorrect please try again!";

cin >> pin2;

}

}

}

void displayMenu(int ch )

{

cout << "[1] Check your account Balance\n"

"[2] Withdraw funds\n"

"[3] Deposit funds\n"

"Please Enter Choice: ";

cin >> ch ;

if (ch != 1 || ch != 2 || ch != 3)

{

cout << "Choice is incorrect, enter choice now: ";

cin >> ch ;

}

}

4 0
3 years ago
Other questions:
  • MATLAB graphics user interface:<br> Describe what Folder, Command Window and Workspace are.
    5·1 answer
  • You have dinner with your family and tell them that you have taken bcis. your mother tells you that she is proud of you and that
    9·1 answer
  • If a simple pipelined processor is super-pipelined by a factor of 3 (the ALU takes 3 cycles instead of one for the smallest oper
    15·1 answer
  • Signs of mastery include?
    10·1 answer
  • Write a function called show_info that takes a name, a home city, and a home state (a total of 3 arguments) and returns a full s
    12·1 answer
  • Image-editing software is used to_____
    7·1 answer
  • Complete the following sentences with the correct form of the verbs in brackets.
    6·1 answer
  • Complete the function to return the factorial of the parameter using recursion,
    10·2 answers
  • Why must web designers select a common font?​
    8·2 answers
  • Which of the following protocols is used by an email client to retrieve messages from an email server, giving users the option t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!