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 most accurate reading that you can take on an analog vom are when the meters pointer is at the?
marshall27 [118]
<span>The most accurate readings are near the right end of the scale, for two reasons. Any inaccuracy in your reading is a smaller part of the total voltage near full scale, and readings near the left end are likely to be off because of incorrect adjustment of the zero adjust screw. If "extreme right" means past the end of the numbers, you may be off there if the needle hits the stop. On meters with a mirror behind the needle, move to where the needle is in front of its reflection for the best reading.</span>
4 0
3 years ago
Question 1 of 1
evablogger [386]

Answer:

Ladders are not moved, shifted, or extended while a worker is on them.

Explanation:

It's the most logical answer out of the others.

3 0
2 years ago
Given a long integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800)
Alexxandr [17]

Answer:

See explanation!

Explanation:

Here we have a program written in C++ language. Each // symbol is a relative comment explaining the reason for each command line (and is not included during the program execution).

<em>The Program: </em>

#include <iostream>

<em>//c++ build in library</em>

using namespace std;

<em>//main code body starts here</em>

int main()

{

 <em> //declare variable to store phone numbers,its area code, prefix and line    number.</em>

  long pnumber;   <em>//declare long variable</em>

  int ac, prefix, lnumber;

 <em> //declare integer variables, where ac: Area Code and lnumber is the Line Number</em>

  cout<<"Enter a 10-digit Phone Number: "<<endl;

  <em>//cout command prints on screen the desired message</em>

  cin>>pnumber;

 <em> //cin command enables the user to interact with the programm and enter information manually</em>

 <em> //main body to obtain the desired output starts below</em>

<em>   //each 'division' is used to allocate the correct value at the correct </em>

<em>   //since prefix is used to get the desired output of ( )    -</em>

  ac = pnumber/10000000;

  prefix = (pnumber/10000)%1000;

  lnumber = pnumber%10000;

 <em> //main body ends here</em>

  cout<<"Based on your 10-digit number"<<endl;

  cout<<"below you have (AreaCode), Prefix, and - line number "<<endl;

  cout<<"("<<ac<<")"<<""<<prefix<<"-"<<lnumber<<endl;

 <em> //Prints on screen the desired output of the long 10 digit Number</em>

  return 0;<em> //ends program</em>

}

-------------------------------------------------------------------------------------------------------

<em>The Output Sample:</em>

Enter a 10-digit Phone Number:

8019004673

Based on your 10-digit number

below you have (Area Code), Prefix, and - line number

(801) 900-4673

<em>....Programm finished with exit code 0</em>

8 0
3 years ago
"Bookings are to be stored in three separate
Zina [86]

Answer:

it is a complete routine of life without it we cannot do time management

Explanation:

mark me brainliest ❤

5 0
3 years ago
On a Windows network share, if the user can add, edit, and delete files and folders within the LabFiles folder, what type of acc
Colt1911 [192]

Answer:

Modify

Explanation:

When people like your family or friends can access a computer, then the need to have permissions would certainly come in handy. There are six basic types of permission one can choose from and the modify option is one of them. It simply grants the holder the ability to read and write files and subfolders and also allows for the deletion of folders and files.

6 0
3 years ago
Other questions:
  • Which company is credited with solving a problem by creating a program that could work on all computers?
    11·1 answer
  • What are some of the good effects of social media
    7·1 answer
  • What command do you type in the search box to access the command line intrface in windows?
    8·1 answer
  • What does Tristan need to do to add a row at the<br> bottom of the table shown?
    6·1 answer
  • 4. When you see ##### in a cell, you should
    14·2 answers
  • Which of the following is the path to the Zoom button?
    8·1 answer
  • Computer science - algorithms - flowcharts
    11·1 answer
  • Rules used by a computer network<br> A network protocol <br> B hierchary protocal<br> C procedure
    7·1 answer
  • With the Linux operating system, its open source design means it can be used, modified and ______
    10·1 answer
  • Complex scientific research is usually done using?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!