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
Print "Censored' if userlnput contains the word "darn, else print userlnput. End with newline. Ex: If userinput is "That darn ca
sasho [114]

Answer:

The code is given below in Java with appropriate comments

Explanation:

//Import the input.

import java.util.Scanner;

class CensoredWords

{

    //Define the main method.

    public static void main(String args[ ])

    {

         //Define the variables.

         String userInput="" ;          

         //Define the scanner object

         Scanner scobj = new Scanner(System.in);

          //Accept the userInput.

         System.out.print("Enter String: ");

         userInput=scobj.nextLine();

         //Check if the input contains darn.

         //Print censored.

         if(userInput.toUpperCase().indexOf("DARN") != -1)

         System.out.printf("Censored");

         //IF the input does not contains darn

         //Print userInput.

         else

System.out.printf(userInput)

         return;

}

}

6 0
3 years ago
Hi Im really a girl and i want to know how to change my username without having to make a new account?
bixtya [17]
No sadly.
You can change your e-mail, profile picture, but that's about it.
I didn't see an option to change your name.

7 0
3 years ago
Read 2 more answers
Suppose x and y are int variables and ch is a char variable. Consider the following input: 5 28 36 What value (if any) is assign
eimsori [14]

Answer:

x is assigned "5", y is assigned "28", and ch is assigned "$"

Explanation:

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

{

   int x,y;

   char ch;

   x = 5;

   y = 28;

   ch = 36;

   cout<<x<<endl<<y<<endl;

   cout<<ch;

   return 0;

}

4 0
3 years ago
Document design techniques make your document easier for readers to skim. Therefore, these techniques give your writing "High Sk
USPshnik [31]

Document design techniques that make your document easier for readers to skim and therefore gives your writing "High Skim Value" is true. The answer is letter A. Documents that give you a high skim value are the headings and subheadings, white space and the toposgraphy.

3 0
3 years ago
Dallas is an analyst at an online retailer. He is great at creating representative diagrams showing the relationships between cu
dimulka [17.4K]

Answer:

The correct answer to the following question will be "Abstract Reasoning".

Explanation:

  • Abstract reasoning depends on the ability to interpret facts, to identify correlations and interactions and to resolve the problems at a deep, conceptual level.
  • To be able to construct hypotheses about both the existence of events and concepts require abstract reasoning capabilities.

This suggests, therefore, that Dallas has this ability.

4 0
3 years ago
Other questions:
  • In which setting would you be least likely to find a full-time A/V technician?
    5·2 answers
  • 15. The text of a desktop publishing document is often created using
    6·2 answers
  • Mary is entering her senior year of college. She has a meeting on Friday with her advisor to discuss her career plans.Mary is al
    15·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    7·1 answer
  • Is a biometric system an input, output, storage or soft device?​
    6·1 answer
  • Please help please I will count your answer brainiest if you help!
    8·1 answer
  • When evaluating platforms, what is the key factor in ensuring a platform addresses an organization's needs?
    8·1 answer
  • EXPLAIN WHY CRYPTOCURRENCIES ARE NOT RELIABLE.
    5·1 answer
  • An operating system with _____ capabilities allows a user to run more than one program concurrently.
    6·1 answer
  • What is the name of the directory that contains symbolic links to unix sysv rc scripts for runlevel 2?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!