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
You are a cleared employee. You discovered fraud and waste of money related to a classified program within your agency. If you r
Irina-Kira [14]

Answer:

A. True.

Explanation:

In this scenario, you are a cleared employee. You discovered fraud and waste of money related to a classified program within your agency. If you report this fraud and waste through appropriate channels, you may receive protection under the Presidential Policy Directive 19 (PPD-19): Protecting Whistleblowers with Access to Classified Information.

In USA, the Presidential Policy Directive 19 (PPD-19) which was signed by President Barack Obama in October 2012, is an executive order designed to provide significant protection for an employee who have access to classified informations such as fraud, waste of money and abuse or prohibiting any form of retaliation against this cleared employee.

3 0
3 years ago
Which answer choice is equivalent to the following decision?
natulia [17]
D. <span>if a > 12 AND b > 8 then output "Yes"
</span>D is the only one that correctly combines those two logic gates. The and statement requires both conditions to be met just as the lengthy piece of code above does.
5 0
3 years ago
If someone you knew was considering installing Smarthome technology, would you advise that person to install it or not? How woul
jeka94
Is this helpful? I would research extensively

5 0
3 years ago
5.   Which of the following attributes of a website indicates a more reliable source for information?
Leona [35]
The answer would be B because ".edu" stands for education and it shows there was a source for the information
5 0
3 years ago
Gino has purchased a secondhand laptop. It came preinstalled with various application software and system tools. Which tools can
Jet001 [13]

Answer:

The answer to this question is given below in the explanation section

Explanation:

This question is about matching the column. So, Gino used the various preinstalled application software and system tools for the following purposes.

Disk cleaner: Gino needs to locate unnecessary files that are taking up a considerable amount of space.

Data recovery:  Gino notices many corrupted files and wants to extract good data from them.

Utility diagnostic program: Gino needs to check the operational status of the computer's hardware and software.

Antivirus: Gino's system is acting odd after browsing the internet, and he needs to scan the system.

7 0
3 years ago
Other questions:
  • list the network characteristics of the wireless network(s) in the decode -- SSIDs, channels used, AP names, presence of Bluetoo
    6·1 answer
  • The structure and organization of data in a database is called a data ____.
    11·1 answer
  • I want pizzzzzzzaaaaaaaaaaa
    9·1 answer
  • Question 2Write a MIPS assembly implementation of the following C/C++ code. Assume small, unsigned integer arithmetic (no range
    10·1 answer
  • A(n) ____ is software that can be used to block access to certain Web sites that contain material deemed inappropriate or offens
    11·1 answer
  • so i just went to play forge of empires and when i logged on to it all of my progress was gone and i was so far in to it
    15·2 answers
  • Julie is purchasing new shoes on a website for her favorite store. Which of the following would indicate that a website is a sec
    6·1 answer
  • Software that displays advertising material when online.
    12·2 answers
  • How are actual rocket launches similar to how balloon rockets and canister rockets launch?
    6·1 answer
  • Create a file using any word processing program or text editor. Write an application that displays the files, name, containing f
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!