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
The lower band and upper band of integer data type​
Nikolay [14]
The whole idea of lower and upper bounds in Integration is that the lower bound represents the smallest value from which we start summing areas(smallest value of the interval) and upper bound is the value to which we sum to(maximum value of the interval).
(Just gave you an answer describing what it was because you didn’t implant a question so I gave you a definition)
3 0
3 years ago
True or False: You cannot change the default margin size for Word documents.  
Veronika [31]
The answer is false because you can change the margin size on words documents.
8 0
3 years ago
. Given an initially empty stack s that accepts integers, the following operations are performed: s.push (10) s.push (20) s.push
sp2606 [1]

Answer:

a) The composition of the stack is :- 80,50,20,10.

Where 80 is the top and 10 is the last element.

b) The sequence of the popped items 40,30,70,60,90.

Explanation:

Stack is LIFO type data structure means Last in First Out.The element inserted last will be out of the stack first.The removal and addition is only at the one end that is top.

First 10,20,30,40 will be inserted in the stack. 40 is a the top.Now two pop operations occurs. 40 and 30 will be removed from the stack.

Now 50,60,70 will be inserted in the stack then again two pop operations so 70 and 60 will be removed from the stack.

Now the stack contains 50,20,10.Top = 50.

80 and 90 are added to the stack and 1 pop operation that is 90 will be removed.

Stack is 80,50,20,10 . Top = 80.

Sequence of integers popped=40,30,70,60,90.

4 0
3 years ago
Which of the following laptop features allows users to overcome keyboard size restrictions?
nataly862011 [7]

Answer:

C. Fn Key

Explanation:

The Fn key represents the function key that used for the dual purpose. It is to be activated with the help of shift key. Also, it controls the functions of the hardware i.e. brightness of the computer or laptop screen, volume of the speaker, etc

Also, it overcomes the restrictions with respect to the size of the keyboard

hence, the correct option is c.  

5 0
3 years ago
A _____ network is where all computers are equal and each one is both data requester and data provider.
andre [41]

Answer:

peer-to-peer network

Explanation:

i think i'm not sure though so tell me if it is wrong :)

8 0
3 years ago
Other questions:
  • Choose the type of critical thinking demonstrated in the example:
    8·2 answers
  • Fill in the blanks. The ________________ donut chart shows the distribution across your website’s pages by the number of clicks
    14·1 answer
  • What is the point of brainy when other people have to answer your questions but not the cumputer
    9·1 answer
  • Select the correct answer.
    10·1 answer
  • A coffee shop is considering accepting orders and payments through their phone app and have decided to use public key encryption
    10·1 answer
  • Select the correct word to complete the sentence
    11·2 answers
  • Technology has had
    10·1 answer
  • C#
    10·1 answer
  • b. Write a complete program for the following situation related to setting the speed of a car to preset values before starting a
    5·1 answer
  • Determine the value of a and b at the end of the following code segment:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!