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
To rearrange the data on your hard disk so your computer can run more efficiently, you use ____.
Ratling [72]
A disk optimization program, but they're probably looking for defragmenting program.
5 0
3 years ago
How do I cancel a friend request?
dusya [7]

Answer:

By pushing cancel

Explanation:

It's simple

3 0
3 years ago
Read 2 more answers
Could somebody please find the bugs and amend them? This question is worth 25 Brainly points!
Andreyy89

line 4

if salary < 30000

error missing ":"

solution

if salary < 30000:

line 6

tax = salary * 0.2

error is missing identifier for tax

solution add identifier for tax on line 3

tax = 0.0

line 11

error syntax

solution is move tax = salary * 0.4 + 6000 to the right

tax = salary * 0.4 + 6000

6 0
3 years ago
High quality pages in a task should all get the same Needs Met rating. For example, a high quality page for a common interpretat
miskamm [114]

Answer:

The given statement is False.

Explanation:

  • Needs Met Rating of a result show us that how much the result is fulfilling the query of the user. The greater the needs met rating is, the greater the satisfaction of the user is.
  • If a page has high quality then it can or can not be useful for the user.
  • If the page has high quality as well as high needs met rating then it is best for the user.
  • If the page has high quality and has low needs met rating that means it is not relevant to the query so not useful for the user.
  • Thus, it is concluded that high quality pages in a task shouldn't all get the same needs met rating rating rather need met rating is dependent upon the relevancy and usefulness of the result to the need and query of the user.
8 0
3 years ago
The marvelous attribute about the gaming industry is that you can create a game in several different programming languages to ma
LenaWriter [7]

Answer:

D syntax

Explanation:

The marvelous attribute about the gaming industry is that you can create a game in several different programming languages to make it more appealing to novice and advanced-level coders. Yet, the unique distinction is that every single programming language has its own syntax.

7 0
2 years ago
Other questions:
  • How many different integers can be represented with a 4-digit number in base 13?
    8·1 answer
  • Implement a recursive program that takes in a number and finds the square of that number through addition. For example if the nu
    5·1 answer
  • Which command is not one of the available Change Case options?
    8·1 answer
  • Before creating a brief to design a product, what is needed
    8·1 answer
  • A common preprocessing step in many natural language processing tasks is text normalization, wherein words are converted to lowe
    15·1 answer
  • Which feature of a blog helps to store and retrieve older posts?
    6·2 answers
  • Where do players resurrect if they have been destroyed in a game?
    13·1 answer
  • The chief intellectual property officer (CIPO) is responsible for collecting, maintaining, and distributing the organization's k
    14·1 answer
  • Can someone please give me timetable managment system with data structures in java?
    11·2 answers
  • Consider the following correct implementation of the selection sort algorithm.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!