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
svet-max [94.6K]
4 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]4 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
What was the first message ever sent in morse code?
JulsSmile [24]
The message was a bible quote "what hath god wrought?"
6 0
3 years ago
Malware that locks or prevents a device from functioning properly until a fee has been paid is known as:
My name is Ann [436]

Answer:

ransomware

Explanation:

3 0
3 years ago
In Scheme, source code is data. Every non-atomic expression is written as a Scheme list, so we can write procedures that manipul
svet-max [94.6K]
What are you saying at the bottom?
7 0
3 years ago
Which of the following connects the processor to the chipset and memory on the motherboard? a. Thread b. FSB c. BIOS d. ALU
IRISSAK [1]

Answer:

The correct Answer is (b) FSB

Explanation:

The chipset is the "superglue" that bonds the microprocessor to the rest of the motherboard and so to the rest of the computer. On a computer, it consists of two basic parts -- the Northbridge and the southbridge. All of the numerous modules of the computer communicate with the CPU over the chipset.

The northbridge joins straight to the processor via the front side bus (FSB). A memory controller is situated on the northbridge, which gives the CPU fast access to the memory. The northbridge also attaches to the AGP or PCI Express bus and to the memory himself.

3 0
4 years ago
What data type would best hold the numeric value?
zaharov [31]

Explanation:

I think option b. integer data type is the suitable answer.

7 0
3 years ago
Other questions:
  • Grace is the sub-editor in a business firm. which feature of a word processing program would she use to make her changes visible
    14·1 answer
  • Makes it possible to distribute both power and data using ethernet cabling. select one:
    12·1 answer
  • You use a __________________ tool to push wires into a keystone jack and cut off the end of the wires.
    7·1 answer
  • Ed has just finished typing a long financial report. Before he sends this report to shareholders, Ed should _____.
    9·2 answers
  • When specifying keywords to conduct an internet search, which of the following parts of speech will be the most useful??
    6·1 answer
  • pharmaceutical company is using blockchain to manage their supply chain. Some of their drugs must be stored at a lower temperatu
    5·2 answers
  • Websites not only give us information, but they also inspire designers in their layouts, illustrations, images, typefaces, and c
    6·1 answer
  • Write a function named days() that determines the number of days since January 1, 1900 for any data passed as a structure. Use t
    5·1 answer
  • Question 1 of 10
    12·1 answer
  • Lists Five Examples of simple statement<br>​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!