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
Plz answer it’s timed
MAVERICK [17]

Answer: the third one

Explanation:

just trust me, the other ones dont mke sense to what I know about the subject, which is a lot

7 0
3 years ago
A(n) _____ is the address of a document or other file accessible on the internet.
Nataly_w [17]

Uniform Resource Locator (URL) is the address of a document or other file accessible on the internet.

<h3>What us URL?</h3>

The address of a document or other file that is accessible via the Internet is known as a Uniform Resource Locator (URL). A hyperlink, often known as a link, is a component that joins two Web pages together.

A web address, also known as a Uniform Resource Locator, is a reference to a web resource that identifies its location on a computer network and a method of retrieval. Though many people mistakenly use the terms "URL" and "Uniform Resource Identifier" interchangeably, a URL is a particular kind of URI.

<h3>How do you write an URL address?</h3>

http://www.example.com/index.html, which denotes a hostname (www.example.com), a protocol (http), and a file name ( index. html ).

To learn more about URL visit:

brainly.com/question/18926479

8 0
1 year ago
A good administrative position to acquire as a stepping stone to further positions is
Andrew [12]

Answer:

A good administrative position to acquire as a stepping stone to future positions is an intern.

Explanation:

When an individual is an intern within an administrative sector, he will be able to learn many concepts and guidelines of this type of work, getting involved in various areas within the sector and accumulating knowledge that will serve him to occupy greater positions within the sector.

In this case, being a trainee is a better option due to the exchange of areas in which he can participate and which will show where his greatest capacities are concentrated within an administrative sector.

4 0
3 years ago
Write the WordSandwich method allSandwiches. This method creates and returns a new array of String objects as follows. Each elem
nalin [4]

Answer:

import java.util.*;

class Main

{

private String[] totalSandwiches(String string1,String string2)

{

int totalElements = string1.length()-1;

String ans[] = new String[totalElements];

for(int i=0;i<totalElements;i++)

{

String temp = "";

for(int j=0;j<=i;j++)

{

temp+=string1.charAt(j);

}

temp+=string2;

for(int j=i+1;j<string1.length();j++)

{

temp+=string1.charAt(j);

}

ans[i] = temp;

}

return ans;

}

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

Main obj = new Main();

String string1,string2;

System.out.print("Enter the 1st String: ");

string1 = sc.nextLine();

while(string1.length()<2)

{

System.out.print("The size of string 1 should be atleast 2 to make a sandwich. Enter the string again: ");

string1 = sc.nextLine();

}

System.out.print("Enter the 2nd String: ");

string2 = sc.nextLine();

while(string2.length()==0)

{

System.out.print("The size of string 2 should be atleast 1 to make a sandwich. Enter the string again: ");

string2 = sc.nextLine();

}

System.out.println("Following are the sandwiches: ");

String ans[] = obj.totalSandwiches(string1,string2);

for(int i=0;i<ans.length;i++)

{

System.out.println(ans[i]);

}

}

}

Explanation:

  • Run a while loop upto the total no. of elements and calculate number of elements from the string1 that should come before string2 .
  • Append the remaining characters of string1 are to temp.
  • The ans array stores the temp at ith index.
  • string1 characters are stored by the variable j.
  • Sandwich is not possible if string1 has less than 2 elements and possible if string2 has no elements.
  • Finally display the sandwich strings.
5 0
3 years ago
Hannah has typed a paper and the last two lines of text are on page two. What feature
BabaBlast [244]

The feature that she should use to prevent the page two and keep all text on one page is;

B: Window/Orphan Control

  • We are told that Hannah wants to prevent the last two lines on of the text from being on a separate page and so the correct answer is window/Orphan Control.

This is because, the feature window/Orphan Control is useful to prevent a single line of a paragraph from being left alone either at the top or bottom of a page. This property is enabled by default for all styles in Microsoft Word as it keeps all the lines of a paragraph together.

Read more on Microsoft Word at; brainly.com/question/6636689

6 0
3 years ago
Other questions:
  • Is a growing network of physical objects that have sensors connected to the internet?
    15·1 answer
  • An athlete runs every day for five days. Write a program that computes the total distance and average distance ran by the athlet
    10·1 answer
  • In a CPMT, a(n) ____ should be a high-level manager with influence and resources that can be used to support the project team, p
    10·1 answer
  • . What is piracy? ???????????????????​
    5·1 answer
  • Convert (0.255)¹⁰ into binary<br>​
    5·1 answer
  • It's 50 points.
    5·2 answers
  • Populate a stack with ten random integers and empty it by showing that the order of the elements is reversed, from last to first
    8·1 answer
  • I’ll give brainliest if answers are correct
    11·1 answer
  • If a packet gets "sucked down a black hole" (figuratively speaking) and is not received by its sender, and no message is sent ba
    10·1 answer
  • What is the current situation of drone technology in emergency rescue and recovery
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!