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
patriot [66]
3 years ago
15

Create a function called makePositive that accepts a single argument: an integer array. The function should walk through the arr

ay and change any negative numbers to positive. You can assume that the array passed to the function will have a 0 at the end of the array. In other words, you do not know the size of the array; you instead know that a certain condition will be true at the end of the array.
Computers and Technology
1 answer:
coldgirl [10]3 years ago
8 0

Answer:

This solution is implemented in C++

void makePositive(int arr[]){

   int i =0;

   while(arr[i]!=0){

       if(arr[i]<0){

           arr[i] = abs(arr[i]);

       }

       i++;

   }

   i = 0;

   while(arr[i]!=0){

    cout<<arr[i]<<" ";

    i++;

}  

}

Explanation:

This defines the function makePositive

void makePositive(int arr[]){

This declares and initializes i to 0

   int i =0;

The following iteration is repeated until the last element in the array

   while(arr[i]!=0){

This checks if current array element is negative

       if(arr[i]<0){

If yes, it changes it to positive

           arr[i] = abs(arr[i]);

       }

The next element is then selected

       i++;

   }

This sets i to 0

   i = 0;

The following iteration prints the updated content of the array

<em>    while(arr[i]!=0){ </em>

<em>     cout<<arr[i]<<" "; </em>

<em>     i++; </em>

<em> }   </em>

}

See attachment for full program which includes the main

Download cpp
You might be interested in
PLZZZZ HELPPP and please don’t send a link , Explain how the processing stage contributes to a computer creating an output.
-Dominant- [34]
The output/interpretation stage is the stage at which data is finally usable to non-data scientists. It is translated, readable, and often in the form of graphs, videos, images, plain text, etc.).
3 0
3 years ago
Subtraction of matrix​
Flura [38]

Answer:

A matrix can only be added to (or subtracted from) another matrix if the two matrices have the same dimensions.

Explanation:

Subtracting matrices Similarly, to subtract matrices, we subtract the corresponding entries. For example, let's consider C = [ 2 8 0 9 ] C=\left[\begin{array}{rr}{2} &8 \\ 0 & 9 \end{array}\right] C=[2089] and D = [ 5 6 11 3 ] D=\left[\begin{array}{rr}{5} &6 \\ 11 & 3 \end{array}\right] D=[51163].

8 0
3 years ago
write a function interest() that takes one input, a floating-point interest rate (e.g., 0.06, which corresponds to a 6% interest
Novay_Z [31]

Code:

def interest():

   interest_rate = 0.06

   investment = input(int('Investment: '))

   yield = 0

   year = 0

   while (yield < investment):

       year += 1

       yield  = investment * interest_rate

   print (year)

NOTE: i wrote this code assuming that the investment for the next year is the same as the first year and so forth

8 0
3 years ago
Jupiter has a very ?<br> surface.
mrs_skeptik [129]
Has a very gassy surface
4 0
3 years ago
The short-term, 0-24 hours, parking fee, F, at an international airport is given by the following formula:  5, if 0 # h # 3 F5
jek_recluse [69]

The following code will program that prompts the user to enter the num- ber of hours a car is parked at the airport and outputs the parking fee.

<u>Explanation:</u>

Code:

#include<iostream>

using namespace std;

int main()

{

float hours;

cout <<"Enter number of hours a car parked at the airport: "; // prompt the user to enter hours.

cin >> hours ; // strong the hours

if (hours > = 0 && hours < =3 ) // if 0 < = h < = 3

cout << "Parking fee: 5"; //printing parking fee is 5.

else if (hours > 3 && hours < = 9)//if 3 < h < = 9

cout<<"Parking fee: "<<6*int(hours);//converting float value to int the multiplying with 6 then printing fee.

else//if 9 < h < = 24

cout<< "Parking fee: 60";// printing parking fee 60.

return 0;

}

6 0
4 years ago
Other questions:
  • The main differences between laptops and desktop computers other than size and portability.
    14·1 answer
  • Assume you're using a three button mouse. to access shortcut menus you would
    10·1 answer
  • Human systems integration (hsi), a supportability issue that every program should consider, addresses such factors as accessibil
    10·1 answer
  • Which of the following would a high school graduate interested in the performing arts most likely do after graduation?
    10·1 answer
  • Among the following, which is the best protection against ransomware?
    8·1 answer
  • Please help with attached file
    8·2 answers
  • True or false? The History list shows only Web pages you visited during the current computing session. -computer essentials
    7·1 answer
  • ITS A VOTE I NEED HELP
    12·1 answer
  • I need a utube name for a gaming channel....PLEASE HELP...BRAINLIEST
    5·1 answer
  • Please solve in 5 mins very fast​
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!