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
melamori03 [73]
2 years ago
6

Given an array arr of type int , along withtwo int variables i and j , write some code thatswaps the values of arr[i] and arr[j]

. Declare anyadditional variables as necessary.
Computers and Technology
1 answer:
nignag [31]2 years ago
4 0

Answer:

Hi! I suppose that no matter the programming language that you need the algorithm, so I will do in pseudo-code.

 

myArray [int] = [1,2,3,4,5,"Hello","World"];

int i = 5;

int j = 2;

// Save the previous value before the swap

aux1 = myArray[i];

aux2 = myArray[j];

// Swap i & j

myArray[j] = aux1;

myArray[i] = aux2;

print(myArray)

// Out : myArray = [1,2,"Hello",4,5,3,"World"]  

Explanation:

The trick is to save in two variables the previous value of the two position before change the array, just like that you can change the array and make the swap without lost the values.

I hope it's help you.

You might be interested in
What is the purpose of an arraignment?
IgorC [24]

Answer:

At an arraignment, the court officially illuminates a litigant regarding charges contained in a prosecution or data, gives the respondent a duplicate of the charging instrument, and takes the litigant's response to those charges as a request.

Explanation:

5 0
3 years ago
Read 2 more answers
Which is a description of phishing?
kodGreya [7K]

Answer:

C. sending emails impersonating legitimate companies in an attempt to learn a recipient's personal information

7 0
2 years ago
This feature in Word Online allows you to view your document to see what it will look like when printed.
kherson [118]

Answer:

Print preview allows you to view your document before printing

7 0
3 years ago
Read 2 more answers
Njdnkjsdnjvnsdjvnjsdnvjsdvnjdnvjdsnvnksn
adoni [48]

Answer:

yes

Explanation:

7 0
2 years ago
How can I download music and films at home without breaking the law?
mina [271]

Answer: use a legal music downloader

Explanation: :)

5 0
2 years ago
Read 2 more answers
Other questions:
  • Your neighbor has moved to another country. He informs you about his new job. You wantto congratulate him by sending an e-mail m
    13·1 answer
  • Operating systems are often written in ________, a very low-level computer programming language that allows the computer to oper
    10·1 answer
  • Which option is used to apply formatting to multiple objects on a single slide while still maintaining the ability to manage the
    14·2 answers
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • Define the proposition in symbols using: p: The weather is bad. q: The trip is cancelled. r: The trip is delayed. Proposition in
    7·1 answer
  • Clearing the computer's cache helps store recently-used information.
    8·1 answer
  • Write programs in python to display “Valid Voter”. (condition : age of person should be
    15·1 answer
  • Arrays of structures ________. Group of answer choices None of the above. are automatically passed by reference cannot be passed
    6·1 answer
  • When you run your Windows Form application, what is the lifespan of a global variable (also known as a "field" or "class" variab
    13·1 answer
  • If two devices simultaneously transmit data on an Ethernet network and a collision occurs, what does each station do in an attem
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!