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
Write the program to solve quadratic equations, but if the discriminant is negative, output
Firdavs [7]

Answer:

PROGRAM  QuadraticEquation Solver

  IMPLICIT  NONE

REAL :: a, b, c ;

  REA :: d ;

  REAL  :: root1, root2 ;

//read in the coefficients a, b and c

  READ(*,*)    a, b, c  

  WRITE(*,*)   'a = ', a

  WRITE(*,*)   'b = ', b

  WRITE(*,*)    'c = ', c

  WRITE(*,*)

// computing the square root of discriminant d

  d = b*b - 4.0*a*c

  IF (d >= 0.0) THEN              //checking if it is solvable?

     d     = SQRT(d)

     root1 = (-b + d)/(2.0*a)     // first root

     root2 = (-b - d)/(2.0*a)     // second root

     WRITE(*,*)  'Roots are ', root1, ' and ', root2

  ELSE                            //complex roots

     WRITE(*,*)  'There is no real roots!'

     WRITE(*,*)  'Discriminant = ', d

  END IF

END PROGRAM  QuadraticEquationSolver

8 0
4 years ago
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store.
astraxan [27]

Complete Question:

Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store. Console Price Comparison Price of 64 oz size: 5.99 Price of 32 oz size: 3.50 Price per oz (64 oz): 0.09 Price per oz (32 oz): 0.11

Using Python

Answer:

<em>This program does not make use of comments (See explanation section)</em>

price64 = float(input("Price of 64 oz size: "))

price32 = float(input("Price of 32 oz size: "))

unit64 = price64/64

unit32 = price32/32

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

if unit64>unit32:

     print("Unit price of 64 oz is greater" )

else:

     print("Unit price of 32 oz is greater" )

Explanation:

This line prompts the user for the price of 64 oz size

price64 = float(input("Price of 64 oz size: "))

This line prompts the user for the price of 32 oz size

price32 = float(input("Price of 32 oz size: "))

This line calculates the unit price of 64 oz size

unit64 = price64/64

This line calculates the unit price of 32 oz size

unit32 = price32/32

This next two lines print the unit prices of both sizes

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

The next line compares the unit prices of both sizes

if unit64>unit32:

This line is executed if the unit price of 64 oz is greater than 32 oz

     print("Unit price of 64 oz is greater" )

else:

This line is executed, if otherwise

     print("Unit price of 32 oz is greater" )

4 0
3 years ago
Which of the following connects the processor to the chipset and memory on the motherboard? a. Thread b. FSB c. BIOS d. ALU
IRISSAK [1]

Answer:

The correct Answer is (b) FSB

Explanation:

The chipset is the "superglue" that bonds the microprocessor to the rest of the motherboard and so to the rest of the computer. On a computer, it consists of two basic parts -- the Northbridge and the southbridge. All of the numerous modules of the computer communicate with the CPU over the chipset.

The northbridge joins straight to the processor via the front side bus (FSB). A memory controller is situated on the northbridge, which gives the CPU fast access to the memory. The northbridge also attaches to the AGP or PCI Express bus and to the memory himself.

3 0
3 years ago
Two technicians are discussing engine valve timing. Technician A says that the optimum valve timing is found through experimenta
nordsb [41]
The answer is B. A only. The optimum valve timing is found through experimentation using an engine dynamometer. The timing of the opening and closing of the valves is called valve timing. So the use of dynamometer measures the power output of a machine that is why it can measure the optimum valve timing.
7 0
3 years ago
Read 2 more answers
If you know the unit prices of two diffferent brands of an item,you are better able to
pantera1 [17]

Answer:

Compare the prices of the two brands.

Explanation:

Price can be defined as the amount of money that is required to be paid by a buyer (customer) to a seller (producer) in order to acquire goods and services.

In sales and marketing, pricing of products is considered to be an essential element of a business firm's marketing mix because place, promotion and product largely depends on it.

One of the importance associated with the pricing of products is that, it improves the image of a business firm.

Hence, if you know the unit prices of two different brands of an item, you are better able to compare the prices of the two brands. Subsequently, the buyer would be able to easily make a decision on which brand's product to purchase.

3 0
3 years ago
Other questions:
  • Brenda is a college student who enjoys downloading music, movies, and television shows from the Internet. She also uses the Inte
    7·1 answer
  • Helpppppp pleaseeeeeee
    5·1 answer
  • What is a main cause of a virus on a computer
    6·1 answer
  • a conpany manufacturers computer screens that utilize less electricity. which form of technology would this be classified as​
    5·1 answer
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    5·1 answer
  • Who killed mrs.huffington
    14·1 answer
  • Given variables first and last, each of which is associated with a str, representing a first and a last name, respectively. Writ
    13·1 answer
  • What should I do if I pluged in my computer charger and it starts making noise and sounds? Plz tell me. Will mark as brainliest
    6·1 answer
  • This is my paragraph . The type of color is ude in this code line is ..............................
    5·1 answer
  • Which are examples of digital video? Choose all that apply.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!