answer.
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
svet-max [94.6K]
2 years ago
12

Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10,

20, 30, 40} becomes {40, 20, 30, 10}.
Computers and Technology
1 answer:
enot [183]2 years ago
3 0

Answer:

This c++ program swaps the first and last elements of the array.

#include <iostream>

using namespace std;

void SwapArrayEnds(int a[], int k);

int main() {

   int len, arr[len];

   int j;    

   cout<<"Enter the size of array" <<endl;

   cin>>len;    

   cout<<"Enter the elements of the array"<<endl;

   for(j=0; j<len; j++)

   {

       cin>>arr[j];

   }    

   cout<<"The elements of the array before swapping are"<<endl;    

   for(j=0; j<len; j++)

   {

       cout<<arr[j]<<"\t";

   }    

   SwapArrayEnds(arr, len);

return 0;

}

void SwapArrayEnds(int a[], int k)

{

   int temp=a[0];

   int l;

   

   a[0]=a[k-1];

   a[k-1]=temp;    

   cout<<endl<<"The elements of the array after swapping are"<<endl;

   for(l=0; l<k; l++)

   {

       cout<<a[l]<<"\t";

   }    

}

OUTPUT

Enter the size of array                                                                                                          

6                                                                                                                                

Enter the elements of the array                                                                                                  

12                                                                                                                              

34                                                                                                                              

56                                                                                                                              

78                                                                                                                              

90                                                                                                                              

23                                                                                                                              

The elements of the array before swapping are                                                                                    

12      34      56      78      90      23                                                                                      

The elements of the array after swapping are                                                                                    

23      34      56      78      90      12

Explanation:

This program accepts user input for both size and elements of the array.

The first and the last element of the array are swapped in another method, SwapArrayEnds.

This method accepts an integer array and another integer variable which shows the size of the array.

The method which accepts parameters is declared as shown.

void SwapArrayEnds(int a[], int k);

In the above declaration, void is the return type. The parameter list contains one integer array followed by the length of that array.

This method is defined as below.

void SwapArrayEnds(int a[], int k)

{

// first element of the array is assigned to another variable

   int temp=a[0];

   int l;    

// last element of the array is assigned to the first index, 0, of the array

   a[0]=a[k-1];

// last index of the array is assigned the original first element of the array copied in temp

   a[k-1]=temp;    

   cout<<endl<<"The elements of the array after swapping are"<<endl;

   for(l=0; l<k; l++)

   {

       cout<<a[l]<<"\t";

   }    

}

You might be interested in
How many solutions exist for the given equation?
vovikov84 [41]
Infinity amount of answers because each side can be simplified to x making any solution correct
6 0
2 years ago
The ________ program displays graphics and loading screens during the boot process.
Minchanka [31]
Booting would be complete if the normal, runtime environment has been achieved. A boot loader is a program that loads operating system for the computer after the completion of power on tests. The boot manager is a program that displays graphics and loading screens during the boot process.
3 0
2 years ago
When looking at security standard and compliance, which three (3) are characteristics of best practices, baselines and framework
Brilliant_brown [7]

Answer:

In order to observe best practices, and to meet with technical and other requirements, organizations often use frameworks for cybersecurity compliance and regulatory compliance. These frameworks provide best practices and guidelines to assist in improving security, optimizing business processes, meeting regulatory requirements, and performing other tasks necessary to achieve specific business objectives such as breaking into a particular market niche or selling to government agencies.

Many such frameworks exist, and the recommendations set out in them can impose difficult and often expensive demands on enterprise resources – especially in situations where an organization is subject to a number of regulatory compliance regimes, whose requirements it has to meet while maintaining its own strong cybersecurity status.

Explanation:

4 0
2 years ago
What are threats to computer system
Readme [11.4K]
Theft or vandalism through to natural disasters are physical threats. Non-physical threats target the software and data on the computer systems, Like hackers or just straight up viruses. Also, untrustworthy apps or games can give your computer viruses as well.
3 0
2 years ago
Kris, an IT manager at Park Infosystems, is handling four projects simultaneously. Each project has loaned and shared resources
Natalija [7]

Answer:

many-to-many relationship

Explanation:

They are different types of relationship between projects. A many-to-many relationship occurs when a row in a table associates with many related rows in another table. For example the relationship between an employee and a project, An employee can work on many projects and a project can have many employees working on it.

8 0
2 years ago
Read 2 more answers
Other questions:
  • how do you make a circuit so 1 switch will turn on/off all the lights(3 lights) and a second switch will change the lights from
    14·2 answers
  • Edria was faced with a situation in which she was given sensitive information about twenty different clients, including their so
    13·2 answers
  • Which references are updated when you copy the formula =$E6-MAX(H$1:J4)
    10·1 answer
  • Lance is at a bus station. His friend is using the ATM machine to withdraw some money. Lance notices a stranger deceptively watc
    6·2 answers
  • Leena needs to manually update the TOC and would prefer not to change the styles in the document.
    9·2 answers
  • True or False: A class that implements an interface may only implement a few of that interface's method declarations
    13·1 answer
  • Based on virtualization technologies, how many types can we classify them? Please give a brief statement on each of them?
    14·1 answer
  • A 2-dimensional 3x3 array of ints, has been created and assigned to tictactoe. Write an expression whose value is true if the el
    10·1 answer
  • If productCost and productPrice are numeric variables, and productName is a string variable, which of the following statements a
    11·1 answer
  • What are ways to enter a formula in Excel? Check all that apply. Click on the Function Library group and select a function from
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!