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
ASAP! WILL MARK BRAINLIEST + 100 POINTS!!<br><br> Match each word to its description.
Naily [24]

When was the Ming dynasty established?

the 1100s CE

the 1200s CE

the 1300s CE

the 1400s CE

4 0
2 years ago
Read 2 more answers
I know this isn't a school question but it is important! how do I get out of hp hardware diagnostics UEFI on hp pc? (step by ste
Debora [2.8K]

Answer:

1. Turn off the computer and wait five seconds.

2. Press the Power button to start the computer and repeatedly press the F10 key to enter the BIOS setup menu.

3. On the BIOS Setup screen, press F9 to select and load the BIOS Setup Default settings.

4. Press F10 to Save and Exit.

5. Use the arrow keys to select Yes, then press Enter when asked Exit Saving Changes?

6. Follow the prompts to restart your computer.

After you have get to the operating system,

1. Press CTRL + Alt + Del on the blank screen.

2. Click on Task Manager

3. Click "File" - "Run a new task" If there is no "file" option, please click on the task manager under the "details"

4. In the pop-up window, enter "msconfig" click "OK"

5. In the system configuration window that appears, click "Service" and uncheck "App Readiness".

6. Click "Apply" --- "OK"

7. In the following window appears to click on the "restart"

6 0
3 years ago
Give two examples of html structure
butalik [34]

Answer:

semantic information that tells a browser how to display a page and mark up the content within a document

7 0
2 years ago
What year does futurist ray kurzweil believe ai will meet human intelligence?.
MariettaO [177]

Answer: 2029

Explanation:

3 0
2 years ago
Flash drives cds external disks are all examples of storage (memory) devices
abruzzese [7]
True; you can store anything up to operating systems on them. Come in handy when transferring data from computer to computer.
8 0
2 years ago
Other questions:
  • Load the titanic sample dataset from the Seaborn library into Python using a Pandas dataframe, and visualize the dataset. Create
    10·1 answer
  • You should structure the<br> first before you search for a relevant picture.
    11·1 answer
  • How do you use bold text?
    5·2 answers
  • In one to two sentences, explain why citizens pay taxes
    8·1 answer
  • All systems have ___________.
    9·2 answers
  • _______ integrates all departments and functions throughout an organization into a single IT system (or integrated set of IT sys
    5·1 answer
  • Ten examples of an interpreter
    8·1 answer
  • After you configure backup settings using the backup plugin, backup jobs will run automatically and start taking backups at the
    13·1 answer
  • Develop Swimlane Activity diagram for Assignment announcement and submission system.
    6·1 answer
  • In a PC, which of the following components stores the BIOS
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!