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
Law Incorporation [45]
2 years ago
8

Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10,

20, 30, 40} becomes {40, 20, 30, 10)
#include
/* Your solution goes here
*/ int main(void) {
const int SORT_ARR_SIZE = 4;
int sortArray[SORT_ARR_SIZE];
int i;
int userNum;
for (i = 0; i < SORT_ARR_SIZE; ++i) {
scanf("%d", &sortArray[i]);
}
SwapArrayEnds(sortArray, SORT_ARR_SIZE);
for (i = 0; i < SORT_ARR_SIZE; ++i) {
printf("%d ", sortArray[i]);
}

Computers and Technology
1 answer:
sergey [27]2 years ago
4 0

Answer:

Here is the SwapArrayEnds()

//function with two parameters; the array and array size

void SwapArrayEnds(int sortArray[],int SORT_ARR_SIZE){  

int temp;   //temporary variable to hold the first element of sortArray

if(SORT_ARR_SIZE > 1){   //if sortArray size is greater than 1

temp = sortArray[0];   // set value of temp to the first element of sortArrray

sortArray[0] = sortArray[SORT_ARR_SIZE-1];   // set the value of first element of sortArray to the last element of sortArray

sortArray[SORT_ARR_SIZE-1] = temp;  }  } // set last element  value to temp

Explanation:

Lets understand the working of the above function with the help of an example. Suppose the sortArray has the following elements: {10,20,30,40}. So the size of this array is 4.

if(SORT_ARR_SIZE > 1) has an if statement which checks if the array size is greater than 1. This condition evaluates to true as 4 > 1. So the body of if condition executes.

Next the statement temp = sortArray[0];   sets the value of temp variable to the value of first element of sortArray. As sortArray[0] means the element at 0-th index position of the sortArray. So using the above example the first element of the array is 10. So temp = 10.

Next the statement sortArray[0] = sortArray[SORT_ARR_SIZE-1];   sets the last element of the sortArray to the position of first element of the sortArray.

SORT_ARR_SIZE-1 is the position of last element of the array. As the size of sortArray is 4, so 4-1 = 3 which points to the last element. Now this element is moved to the first position of the array. This means that the value of first element of array becomes 40 as the element at 3-th index of the sortArray is 40.

Next the statement sortArray[SORT_ARR_SIZE-1] = temp moves the value in temp variable to the last position of the sortArray. As we know that the value of temp= 10. So this element 10 of the sortArray is positioned at SORT_ARR_SIZE-1 position of sortArray which is 4-1 = 3-th index of sortArray. This simply means that 10 is moved to the last position of sortArray.

So now the final sortArray becomes: 40,20,30,10 as the first and last element of the array are swapped using above function SwapArrayEnds().

The program along with the output is attached in screenshot.

You might be interested in
By definition, a computer
lapo4ka [179]

Answer has a screen

Explanation:

a computer has a screen

5 0
2 years ago
What is the transfer rate of DDR memory?
hoa [83]

DDR memory is 64-bit so that means that it is 64

5 0
2 years ago
On average, someone with a Bachelor's degree is estimated to earn ____ times more than someone with a high school diploma.
oee [108]
The correct answer is <span>B)</span> 1.4

It can be difficult to become a high earner in the U.S without a college degree. Those with a high school diploma or less are the lowest earners on average. According to research, average yearly earnings for someone with a bachelor’s degree are $59,124 as compared to someone with a high school diploma who earns an average of $35,256 per year. Thus, at the end of the day, the amount of money does become significant.



5 0
3 years ago
I just want a refund please. Thank you
Nina [5.8K]
Unfortunately you can’t be refunded points. Sorry :(
7 0
2 years ago
In the earliest stages of human history, what was the only medium?
alexdok [17]

The only medium that was used for the dissemination of information during the earliest stages of human history is: C. the human body.

Information sharing is an integral part of human life because no human is able to live comfortably in isolation without the need to share or receive messages from others through a particular medium, especially for awareness, growth, development and proper decision making.

Prior to the medieval period, which is the earliest stage of human history, the human body serve extensively as the only medium that was used for the dissemination of information from one person to another.

This ultimately implies that, various symbols, signs and objects that were  mutually understandable to the people were drawn or written on human body, so as to serve as a medium during the process of communication.

Read more: brainly.com/question/14810228

8 0
2 years ago
Other questions:
  • Which program can damage your computer
    13·2 answers
  • If Number = 7, what will be displayed after code corresponding to the following pseudocode is run? (In the answer options, new l
    5·1 answer
  • Read the scenario below and then answer the
    14·1 answer
  • Arrange the steps in the process of manually installing software.
    6·1 answer
  • What is the difference between a design pattern and a DLL?
    12·1 answer
  • HELP ASAP!Select all examples of desirable workplace skills, habits, and attitudes.
    7·1 answer
  • A blogger writes that the new "U-Phone" is superior to any other on the market. Before buying the U-Phone based on this review,
    7·2 answers
  • Does anyone have a rbx account? If they do friend request Tribalchief777
    8·1 answer
  • CS160 Computer Science I In class Lab 10
    15·1 answer
  • Programs that do the same thing every time they run are called...
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!