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
zepelin [54]
3 years ago
10

Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the num

ber of elements in the array. The function reverses the elements of the array. The function does not return a value.So far I have this and it's telling me that I am not reversing all the elements. I think it might be an offset issue.My code so far:void reverse (int a[], int x){int swap;for (int i=0; i<=x; i++){swap = a[i];a[i] = a[x];a[x] = swap;}return;}
Computers and Technology
1 answer:
Charra [1.4K]3 years ago
3 0

Answer:

To reverse the elements in an array, the codes can be written as follows:

void reverse(int a[], int x)

{

       int swap;

       for(int i = 0; i < x/2 ; i++)

       {

           swap = a[i];

           a[i] = a[x - i - 1];

           a[x - i - 1] = swap;

       }

}

Explanation:

There are two aspects that are worth for our concern:

First, in the for-loop, the condition should be set as "x / 2".  In every iteration, there are two numbers in the array being swapped.

  • a[0] swapped with a[x-1]
  • a[1] swapped with a[x - 2]
  • a[2] swapped with a[x - 3]
  • .....

All the elements in the array shall complete swapping when it reaches its middle index.

Second, to ensure we always take the element from the last and followed with the second last, third last etc in next round of iteration, we need to formulate the index as "x - i - 1"

You might be interested in
Why are there 2 types of ip addresses like 172.16.254.1 or 2001:db8:0:1234:0:567:8:1?
solong [7]
The first example is an IPv4 address. Because IPv4 is only 32 bits long there are only about 4 billion addresses available. To expand the address space IPv6 came into existence and your second example is an IPv6 address.
7 0
3 years ago
What part of the System Model is a Flow Chart primarily developed for?
Morgarella [4.7K]

A, I believe... I could be wrong

3 0
4 years ago
Question 6 (2 points)
OLga [1]

Answer:

It is all of the above

Explanation:

Technology is seen everywhere like in DVD player , a new medical treatment and skills needed to purify water

4 0
3 years ago
Which routine is configured to execute first when the program runs?
tester [92]
It's D because of ok
4 0
3 years ago
Write a method maxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the method in a pr
klio [65]

Answer:

See the code snippet below

Explanation:

import java.util.Scanner;

public class LabProgram{

     public static void main(String[] args){

          Scanner scan = new Scanner(System.in);

          System.out.println("Please enter first number: ");

          int firstNumber = scan.nextInt();

          System.out.println("Please enter second number: ");

          int secondNumber = scan.nextInt();

          maxMagnitude(firstNumber, secondNumber);

}

     public static int maxMagnitude(int firstValue, secondValue){

         System.out.println(Math.max(firstValue, secondValue));

}

}

6 0
3 years ago
Other questions:
  • A device that modulates digital data onto an analog signal and then demodulates the analog signal back to digital data is a ____
    8·1 answer
  • Question # 4
    8·2 answers
  • What icon is usually used to indicate an attachment feature?
    14·2 answers
  • Work-based learning can be defined as educational experiences that focus on
    11·1 answer
  • What should be included in research for a problem statement? Select all that apply
    13·2 answers
  • The SPF strategy can be proven to be optimal in the sense that it minimizes average response times. In this problem, you will de
    10·1 answer
  • Hannah wants to write a book about how scientists and society interact, and she has generated ideas for chapters. Which chapter
    13·1 answer
  • List resource you can utilize if you are experiencing technology issued
    5·1 answer
  • Which federal legislation requires lending companies to notify consumers of changes in rates and fees?
    12·1 answer
  • Which type of a computer can be assembled using a monitor, a keyboard, a cpu, speakers, a printer and a mouse?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!