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
yulyashka [42]
3 years ago
8

1. Create an array of ints with 20 elements. With a random number generator, seeded with time, assign a random number between 1

and 100 to each element of the array. Using the selection sort algorithm discussed in class, sort the array from smallest to largest. The sorting of the array should be done inside a user defined function. This function should not return any values to main using a return statement. It should have the following parameters: the array, and the number of elements in the array. Only the sorting should be done in the function. Everything else (including the random number generation, the printing of pre-sorted array, and the printing of the post-sorted array) should be executed in main. Print to the screen the array in a single line before it is sorted. Print to the screen the array in a single line after it is sorted. Sample output on a similar problem with a 5 element array is: Original array 36 47 54 82 15 Sorted array 15 36 47 54 82

Computers and Technology
1 answer:
nikdorinn [45]3 years ago
5 0

Answer:

#include <iostream>

#include<time.h>

using namespace std;

void sort(int a[20],int n)   //selection sort

{

   int i,j,temp;

   for(i=0;i<n;i++)        

   {

       for(j=i+1;j<n;j++)  //finds minimum element

       {

           if(a[i]>a[j])     //swaps minimum element to its right place

           {

               temp=a[i];

               a[i]=a[j];

               a[j]=temp;

           }

       }

   }

}

int main()

{

   srand(time(NULL));

   int arr[20],n=20,i;

   for(i=0;i<n;i++)

       arr[i]=rand() % 100 + 1;    //assigns random number to each array element

   cout<<"Before sorting\n";

   for(i=0;i<n;i++)

       cout<<arr[i]<<" ";   //prints array before calling sort func

   sort(arr,20);     //sort the passed array

   cout<<"\nAfter sorting\n";

   for(i=0;i<n;i++)

       cout<<arr[i]<<" ";  //prints array after sorting

   return 0;

}

OUTPUT :

Please find the attachment below.

Explanation:

The program above first assigns random number from 1 to 100 to each element of array using rand(). srand(time(NULL)) is used to generate new number every time otherwise same random number will be produced at a time. Then sorting method is called in which selection sort algorithm is used.

Selection sort algorithm finds the minimum element in each pass and place it into its right position. For example - 34,54,12,5 is passed

After Pass 1 - 5  54  12  34

After Pass 2 - 5  12  54  34

After Pass 3 -  5  12  34  54

You might be interested in
Question 1
Alexxandr [17]

Explanation:

so, what do you think ?

I am sure you have used a computer or a smart phone yourself.

how many clicks or taps do you want to do before you you get what you were looking for ?

hmmmm ?

as few a possible, right ?

ideally, of course, this is one (1) click or tap.

7 0
2 years ago
Sorts by value in reverse order; keeps the same key
KATRIN_1 [288]

Answer:

rsort()

Explanation:

the sorting function is used to sort the elements in the array.

the sorting can be increasing or decreasing, depends on the function used.

let discuss the option:

a. sort()

this is the sorting function, it used to sort the array in ascending order.

b. arsort()

this is also sorting function, it used to sort the associated array in descending order according to the value.

d. asort()

this is also sorting function, it used to sort the associated array in ascending order according to the value.

c. rsort()

this is the sorting function, it used to sort the array in descending order.

Therefore, the correct answer is rsort().

4 0
3 years ago
In a remote control,infrared light( )to control TV<br>a.are used b.is used c.was used​
schepotkina [342]
B. Is used
If this is not the full statement it may be C
6 0
3 years ago
Brandon has configured one of the applications hosted on his cloud service provider to increase the number of resources as neede
goldenfox [79]

Answer:

The description of this capability is:

d. Horizontal scaling

Explanation:

The capability that Brandon has achieved is horizontal scaling, which involves the increasing of the resources of cloud applications to meet his increasing demand for cloud services.  Vertical scaling involves the addition or subtraction of power to a cloud server, which practically upgrades the memory, storage, or processing power.  But to scale horizontally, more resources are added or subtracted.  The purpose of horizontal scaling is to spread out or in the workload of existing resources and either increase or decrease overall performance and capacity.

8 0
3 years ago
When checking an id, a server notices a tear in the lamination covering the id, but the other features appear to be valid. the s
KatRina [158]

Answer:

server must ask for a second ID

Explanation:

Based on the information provided within the question it can be said that in this scenario the server must ask for a second ID. If the individual provides a second ID make sure that it is valid. If the individual cannot provide a second ID service can be denied since the ID may have been tampered with since the lamination is coming off.

7 0
3 years ago
Other questions:
  • Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
    11·2 answers
  • Which of the following is NOT an example of a font style?
    13·1 answer
  • George and Miguel want to know more about their local and online competitors and about the retail industry. What is the best way
    9·1 answer
  • All computers can support multiple internal hard drives. <br><br> a. True <br><br> b. False
    13·1 answer
  • C++ CODE
    6·1 answer
  • Research shows that a passive close to a cover letter leads to more interviews. Please select the best answer from the choices p
    8·2 answers
  • Complete the following sentences with the correct form of the verbs in brackets.
    6·1 answer
  • Tamera was responding to a complaint that one of the employees is having problems with the wired network connection on their lap
    8·1 answer
  • Which of the following are drivers of machine learning growth?
    15·1 answer
  • System development life cycle
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!