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
In five to ten sentences, explain what netiquette is and how it improves efficiency and productivity in the workplace.
dlinn [17]

Netiquette is a form of communication done correctly online. Good netiquette involves respecting others privacy, using correct grammar, and not doing anything online that will annoy or disrupt others. It is important to have netiquette while online, because communication online is non verbal and you can’t tell how someone is reacting. Having netiquette is important. It implies that you have polite behaviors, and want to build up relationships with people in your work space or at a party you plan on attending. Netiquette is one way to show respect to a person, and to show that you deserve respect. It improves how you organize your writing, and shows how productive you can be. By helping you to become polite online and respectful to other users of the internet, Netiquette is especially important for future letters, emails, or other writing forms.


4 0
3 years ago
Read 2 more answers
Anyone help me please​
MissTica

Answer:

1. True

2. False

3. True

4. False

5. True

6. True

7. False

4 0
3 years ago
Read 2 more answers
What is the purpose of netiquette guidelines?
sp2606 [1]
The purpose of netiquette guidlelines is to provide a safe and secure environment for internet users everywhere
7 0
3 years ago
A fast-food restaurant has four kinds of employees:
Marysya12 [62]

Answer:

Following is given the detailed solution of the given question.

I hope it will help you!

Explanation:

7 0
3 years ago
Place the following discoverers in the correct chronological order of the timeframe for their discoveries, from earliest to most
Alex787 [66]
The correct order or answer is the 2nd choice.

Pythagoras, Gauss, Edison, Hawking. The following are the most noted discoveries of each.

Pythagoras, 500 B.C. School Of Mathematics and Pythagorean theorem.Edison, Year 1879 - Invention of incandescent light bulb.Gauss, Year 1801 - Therom of Alegbraic Solution. Stephen Hawking Year1980 - Studies in cosmology particularly contributing to the context of black holes.
5 0
3 years ago
Other questions:
  • What inventor patented the first American movie projector?
    14·2 answers
  • Blank includes websites that encourage interaction and connection among people ,business and organizations
    13·1 answer
  • (Help please I don't know what to choose because it's both text and email but I can only pick one. HELP!!!!!!!!!!)
    6·2 answers
  • Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and releas
    13·1 answer
  • In science class, Patricia is giving a presentation on the different types of flowers in her community. As part of her presentat
    5·1 answer
  • The technology dealing with robots is called
    6·1 answer
  • A sum of JS300 is divided in the ratio 2:3.
    9·1 answer
  • Write a menu-based program in C++ for an input restricted dequeue using Linked List consist of
    9·1 answer
  • What are the two types of electronic components
    15·2 answers
  • Which statement best describes what happens when a computer starts?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!