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
Operating systems are designed to work with specific hardware. Which operating system works with Apple computers?
Ghella [55]
2. Mac and to be more precisely, OS X
5 0
3 years ago
Read 2 more answers
1. Answer the following questions: a. What are the different types of number system? Name them.​
BigorU [14]

Answer:

binary,decimal, hexadecimal and octal number system

5 0
2 years ago
Which extra step do verizon devices require for fenrir to be allowed to connect to the device?
madam [21]

Differentiation creates a competitive edge based on the distinctiveness of the product. Uniqueness is created by a variety of potential factors.

<h3>What is the Verizon device program?</h3>

The program for device payments: requires you to sign a contract promising to pay for the item in regular installments until the balance is paid. You have the option of paying the gadget off in full at any moment, or you can pay the installments over the course of the entire term.

Instead of paying for your equipment in full up front, Verizon device payment allows you the freedom to upgrade early and spread out your payments over 36 months. Until the full retail price of your item is paid off, you'll make manageable monthly payments.

Differentiation is Verizon's general business approach. Differentiation creates a competitive edge based on the distinctiveness of the product. Uniqueness is created by a variety of potential factors.

To learn more about the Verizon device program refer to:

brainly.com/question/13696647

#SPJ4

8 0
1 year ago
Think about the pseudocode that you developed for your adventure game in this unit. Would it have been easier to create a flowch
katovenus [111]

Answer:

it may not be easy

Explanation:

because am using a phone not a cuputer

5 0
2 years ago
Microsoft, Intuit and, Yahoo are building new facilities in Quincy, WA, a town that previously had a population of 3,500. Along
sveticcg [70]

Answer:

Economic.

Explanation:

In the following scenario, In Quincy, WA, a community that formerly would have a community of 3,500, they are developing new infrastructure. In addition to such friends and neighbors, Quincy citizens will also be seeing more traffic signals, a shopping center, rising property prices, and new opportunities.

So, the following scenario is best suited for the economic changes.

5 0
3 years ago
Other questions:
  • Write a program that checks for car mileage. if the mileage is greater than 100000, display "clunker!". if not, display "buy it!
    7·1 answer
  • To save and store data separate from a computer, it helps to have an
    15·2 answers
  • Given an array arr of type int , along withtwo int variables i and j , write some code thatswaps the values of arr[i] and arr[j]
    6·1 answer
  • A system administrator is selecting an operating system for use by the company’s research and development team. The team require
    15·1 answer
  • When entering data in Access if the data is entered using an Access form, that data is stored in a table or tables. TRUE FALSE
    12·1 answer
  • Write a for loop that runs 5 times and accepts the input of an integer number every time. Those numbers will be accumulated by a
    7·1 answer
  • Help it don’t let me click what do I do
    13·1 answer
  • time to throw poggers xqc time to throw pogchamp time to throw pogchamp time to throw pogchamp time to throw pogchamp time to th
    5·2 answers
  • What happens if a computer lags too much?
    14·2 answers
  • What is the maximum ream size on an agile project?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!