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
Is anybody willing to gift me V bucks? Gamer tag: SpiffyPlop
maxonik [38]

no. use ur own money ???? :D

3 0
3 years ago
Read 2 more answers
One line of code is missing (marked in
Harman [31]

Answer: num1.plus(1);

Explanation:

4 0
3 years ago
In addition to configuring software, and it staff can create a user ____, which includes screens, commands, controls, and featur
WINSTONCH [101]

Answer:

User Interface

Explanation:

A user interface is what you see in front of your display screen. All those commands, controls, and features you interact with are all user interfaces. The programmer does both the backend and frontend coding and delivers the UI for the users to interact with mobile devices or machines and complete tasks.

5 0
4 years ago
Waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
True [87]

Answer:

AGGHHHHHHHHHHHHHHHHHHHGHGHHHHHH

Explanation:

8 0
3 years ago
Read 2 more answers
The application that Scott is writing has a flaw that occurs when two operations are attempted at the same time, resulting in un
Luden [163]

The type of flaw that the application is said to  have is known to be called race condition.

<h3>What is meant by race condition?</h3>

A race condition is known to be a form of unwanted situation that takes place when a device or system tries to carry out two or more operations at the same given time, but due to the nature of the device or system, the operations had to b be done in the right sequence to be carried out correctly.

Therefore, The type of flaw that the application is said to  have is known to be called race condition.

Learn more about race condition from

brainly.com/question/13445523

#SPJ1

3 0
2 years ago
Read 2 more answers
Other questions:
  • What is the most efficient way to include a space after each paragraph?
    13·2 answers
  • You are starting a spreadsheet, and you would like 500 to appear in cell C3. You should _____.
    11·2 answers
  • A(n) ______________________________ is a camera mount that uses the concept of a lever and fulcrum and allows a camera to be rai
    9·1 answer
  • Write a program that implement a bubble sort ?
    5·1 answer
  • All conductors,buses,and connections should be considered
    13·1 answer
  • Complete the firstMiddleLast() function to return a new string with the first, middle, and last character from string. If string
    9·1 answer
  • Is the Internet dangerous?
    10·2 answers
  • Which term means a cryptography mechanism that hides secret communications within various forms of data?.
    6·1 answer
  • Please help me on this it’s due now
    5·1 answer
  • When using a self-contained recovery device on a cfc, hcfc, or hfc system with an operating compressor, technicians must?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!