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
How to be fluent in computer
Setler79 [48]

Explanation:

1. Seeing people do technological innovations, so you have some motivation and inspiration to be fluent in computer

2. Try experimenting and trying stuff, like trying to learn how to code, how the internet work, etc.

3. work more with computers, for example, make a note with OneNote, making digital art with blender, adobe illustrator etc.

4. Try to learn how to be better at learning computer, like, if you do mistakes in your learning journey, try to avoid it next time

5. good luck ;)

7 0
2 years ago
Read 2 more answers
Rectangular box formed when each column meet​
Over [174]

Answer:

If this is a true or false I guess my answer is true?

Explanation:

3 0
2 years ago
File formats are linked to certain programs.<br><br> True<br> False
Lostsunrise [7]
What was the answer?
7 0
3 years ago
Read 2 more answers
During active listening, which response is NOT an example of providing feedback to the speaker to show that you understand his o
MaRussiya [10]

Answer:

The answer is D.

Explanation:

They/you are asking the speaker to clarify what they just said.

6 0
3 years ago
Which of the following steps should you take after attending a college fair?
leonid [27]

D. Make a decision about which colleges to attend that night.

5 0
3 years ago
Read 2 more answers
Other questions:
  • You want to deploy software using group policy. what is necessary before deciding to assign the software to your user accounts?
    11·1 answer
  • What will be returned when the following SQL statement is executed?
    5·2 answers
  • Sam has sent Sally an email. Sally wants to answer him without manually typing in his email address. Which email option should s
    12·2 answers
  • Hot five was the famous band of which musician?
    14·1 answer
  • In a computerized accounting system, each transaction that is analyzed must be entered by hand into the appropriate journal and
    12·2 answers
  • I need some help pleas hurry
    5·1 answer
  • ppose we have a Rectangle class that includes length and width attributes, of type int, both set by the constructor. Define an e
    9·1 answer
  • When writing research questions, use action words, such as
    6·2 answers
  • Question #5
    11·2 answers
  • Which of the following is not a component of Power BI?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!