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
klio [65]
3 years ago
15

Write a method swaparrayends() that swaps the first and last elements of its array parameter. ex: sortarray = {10, 20, 30, 40} b

ecomes {40, 20, 30, 10}. the array's size may differ from 4.
Computers and Technology
1 answer:
Alexus [3.1K]3 years ago
3 0
In the C programming language, you can't determine the array size from the parameter, so you have to pass it in as an extra parameter. The solution could be:

#include <stdio.h>

void swaparrayends(int arr[], int nrElements)
{
int temp = arr[0];
arr[0] = arr[nrElements - 1];
arr[nrElements - 1] = temp;
}


void main()
{
int i;
int myArray[] = { 1,2,3,4,5 };
int nrElements = sizeof(myArray) / sizeof(myArray[0]);
swaparrayends(myArray, nrElements);

for (i = 0; i < nrElements; i++)
{
printf("%d ", myArray[i]);
}

getchar();
}

In higher languages like C# it becomes much simpler:

        static void Main(string[] args)
        {
            int[] myArray = {1, 2, 3, 4, 5};
            swaparrayends(myArray);
            foreach (var el in myArray)
            {
                Console.Write(el + " ");
            }

            Console.ReadLine();
        }

        static void swaparrayends(int[] arr)
        {
            int temp = arr[0];
            arr[0] = arr.Last();
            arr[arr.Length - 1] = temp;
        }

You might be interested in
One way bloggers decide how to present information is by understanding
PSYCHO15rus [73]

I would say strong use of multimedia.

4 0
3 years ago
Read 2 more answers
The windows troubleshooting utility that identifies and eliminates nonessential files is called _____.
Virty [35]
I think it is Defragment
8 0
3 years ago
Read 2 more answers
What makes manually cleaning data challenging?
Alexxandr [17]

Manually cleaning data is done manually which makes it challenging. This make it prone to mistakes.

6 0
3 years ago
Save an image as a separate file by right-clicking the image and then clicking this option at the
Olenka [21]

Answer:

Save image as

Explanation:

6 0
3 years ago
Read 2 more answers
Software ________ defines the permissions, rights, and restrictions assigned to the person who purchases a copy of software.
Lesechka [4]
The answer to this question would be "Licensing"
3 0
3 years ago
Other questions:
  • In the Remote Access Domain, if private data or confidential data is compromised remotely, you should set automatic blocking for
    5·1 answer
  • Which of the following is the strongest password? Xo795&amp;A &amp;cGo9Tz F5h#3u9g vU7#$3T sC9$d&amp;cF5h#3u9g
    13·2 answers
  • Free points! your welcome
    9·2 answers
  • my airpods just do not seem to connect if i try to pair them, reset them, they have this continuous green light, please help me
    12·1 answer
  • Write a program that asks for the weight of a package and the distance it is to be shipped. This information should be passed to
    12·1 answer
  • Who can provide you with a new password when you have forgotten your old one?
    14·2 answers
  • You can use pen and highlighter tools to emphasize information on a slide during a PowerPoint presentation. These tools are avai
    11·1 answer
  • You are system administrator with hundreds of host workstations to manage and maintain. You need to enable hosts on your network
    14·1 answer
  • Which of the following statements are true regarding models? Select 3 options.
    11·1 answer
  • Question 8 A data analyst is working with a data frame named stores. It has separate columns for city (city) and state (state).
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!