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]
3 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]3 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
A numbered list is best suited for steps that need to be done in _______________________ . [Create Bulleted and Numbered Lists]
kap26 [50]

Answer:

Order.

Explanation:

Microsoft Word refers to a word processing software application or program developed by Microsoft Inc. to enable its users to type, format and save text-based documents.

In Microsoft Word 2019, the users are availed with the ability to edit the word document in the following view type;

I. View Mode.

II. Print Mode.

III. Drift Layout.

A numbered list can be defined as a list of items that are ordered numerically or sorted sequentially.

A numbered list is best suited for steps that need to be done in order, usually in an ascending order. Thus, a numbered list is an ordered list that starts from 1.

To create a numbered list in Microsoft Word, you should press 1 followed by a period, leave a space, type a text and then press the enter button.

5 0
3 years ago
Jerry keeps a spreadsheet of all the tools he owns. He wants to figure out
Evgen [1.6K]

Answer:

It's B and C

Explanation:

As because first you have to write the formula in any cell like to write the total if u want to to write in negative than it's B and If u want in positive than it's C. And see the above pictures to get it perfectly

7 0
3 years ago
Read 2 more answers
A disadvantage of creating a website with tables, without CSS is
ikadub [295]
I am just gonna yolo it... <span>each table has to be updated individually </span>
6 0
3 years ago
Read 2 more answers
What makes these Pokémon special?
Otrada [13]

Answer:

Charizard is a fire type dragon that is orange Blastoise is a big turtle that's water type Charmander is a fire type dinosaur the first evolution of Charizard Ivysaur is a grass type Turtle looking thing and the last one is a glitch

8 0
3 years ago
Read 2 more answers
In what way, if any, can your social media presence affect your chances of getting a job in social media?
Leno4ka [110]

Answer:

Your social media postings can help you secure a job too, not just it being effective in a bad way.

Explanation:

Your content can give hiring managers an overall idea of your personality, what you are passionate about, how you interact with people in group discussions and how previous colleagues feel about you through recommendations and so on. All of these give you an advantage in securing a job.

7 0
2 years ago
Other questions:
  • A(n) __________________ device is a breath analyzer on your vehicle that is electronically connected to the ignition.
    11·1 answer
  • Your friend wants to know about Microsoft Expression Web 4. Which of the following terms will you use to describe Microsoft Expr
    5·1 answer
  • Meadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual
    6·1 answer
  • Web 2.0 has led to a shift just from consuming content towards what
    6·1 answer
  • A typical analog cell phone has a frequency of 850 mhz; a digital phone a frequency of 1950 mhz. compared to the signal from an
    7·1 answer
  • Which commands can be used to highlight a whole paragraph? Check all that apply.
    6·1 answer
  • After reviewing device security you learn that a malicious user in an airport
    14·1 answer
  • You want to search for contacts in your email program. You enter the person’s first name and last name in the search box. You wa
    10·2 answers
  • Which symbol shows an input?
    13·1 answer
  • The (blank) option will help determine the overall look of her presentation.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!