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
What's the biggest security issue with using social networking sites to market your listings?
Savatey [412]

The biggest security issue with using social networking sites to market your listings is Criminals may use social networking sites to identify your personal data.

<h3>What is a social marketing site?</h3>

A social marketing site is a site where people from around the world are connected in one place and share their thoughts and photos and other data.

The social sites are on the internet and there is a chance of stealing data and it identity theft, phishing, online predators, internet fraud, and other cybercriminal attacks are also some risks.

Thus, the largest security concern with using social networking sites to sell your listings is that thieves could use these sites to find personal information about you.

To learn more about social marketing sites, refer to the link:

brainly.com/question/15051868

#SPJ4

6 0
1 year ago
Jake is preparing his resume. He is applying for the position of iOS application developer at a large software company. He wants
gavmur [86]

Answer:

C. Modern Programming Language Skills

Explanation:

4 0
2 years ago
I need the answer to the below question *ASAP*
Mashutka [201]

2 4 9

Explanation:

Basically what I thought was the way was, since 2 is first, then its 1, then since 4 is second, it's added second, lastly to get the last oneI added them all and got 9 so that's third.

4 0
3 years ago
Read 2 more answers
Carl is a music teacher. He builds custom computer systems for his students to use when they are learning and creating music. Ca
shutvik [7]

Answer:

um ahh <em> </em><em>badl</em><em>y</em><em> </em>

Explanation:

i really don't know the answer

4 0
2 years ago
What is an unintended consequence of pesticides used on crops
RUDIKE [14]
<span>They leave a residue on the surface or inside the crop treated. </span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • Paragraph talking about why i chose bill gates
    10·1 answer
  • What type of organism forms the base of food webs?
    9·1 answer
  • How has science fiction influenced technology
    7·2 answers
  • Which of the following statements is true of intrapreneurs
    15·1 answer
  • 5. RAM IS YOUR SYSTEM’S-
    14·2 answers
  • Software as a Service (SaaS) refers to the use of computing resources, including software and data storage, on the Internet rath
    13·1 answer
  • Which of the following is a default letter assigned for the primary hard drive
    6·2 answers
  • Always follow the routine "clean up while in use and clean up before keeping it".
    6·1 answer
  • Maria is creating a program where the user will enter their name to begin. What kind of variable should be used for the user’s n
    15·2 answers
  • What is the output of the following code snippet if the variable named cost contains 100? if cost &lt; 70 or cost &gt; 150 : dis
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!