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
Rewriting notes into complete sentences is unnecessary if you want to include the notes in your study guide. Truth or false?
goldfiish [28.3K]

The answer would be true. They're notes, so you don't need it to be written perfectly.

Edit: How would this be incorrect? A study guide is a personal thing, and so are notes. So long as you understand the notes, they don't need to be written as perfectly as an essay would.

4 0
3 years ago
Read 2 more answers
Select two netiquette guidelines. In a paragraph of no less than 125 words, explain why these guidelines make professional onlin
Paladinen [302]

Respect others.

This means that it is important to make sure that your interactions with other internet users are based on respect for each other's resources. This includes time, bandwidth, and even emotions. Ensure that the information you are sharing is of value to the intended recipients and is sent in a timely manner. Treat other online users as you'd have them treat you.

Visualize your online conversations as you would real life conversations. Avoid being offensive and be accommodating of other peoples shortcomings. Also keep in mind who is part of the forum you are interacting with so as to use appropriate language. 



4 0
2 years ago
Most languages allow a specialized selection structure called the ____ structure when there are several distinct possible values
aleksandr82 [10.1K]

Answer:

CASE

Explanation:

Case Structure is a mechanism that allows different executions when there are several distinct possible values for a single variable, and each value requires a different subsequent action depending on the value of the label.

Case structure is also a conditional control structure that appears in most modern programming languages and allows a selection to be made between several sets of program statements.

8 0
3 years ago
Unscramble thr words <br>1.Nsieg Wiev<br>2.Seeathdat ievw​
valentinak56 [21]

Answer: genis view       headset view

Explanation:

6 0
2 years ago
Read 2 more answers
Importing data is sending data to a new file.Is this true or false
Kipish [7]

false homie I gotcho


3 0
3 years ago
Read 2 more answers
Other questions:
  • TCP is the protocol responsible for the delivery of data on the Internet, and IP provides addresses and routing information.
    12·1 answer
  • Greg is the network administrator for a large stadium that hosts many events throughout the course of the year. They equip usher
    7·1 answer
  • The first idea for a communications network was called
    14·2 answers
  • You are the leader of a team at work. What type of leader would you like to be – one that gets involved and works with the team
    15·2 answers
  • A personal computer (pc) or ____ is a small computer system designed to be used by one person at a time.
    12·1 answer
  • HELP AASAP BRAINLIEST JUST HELP
    13·1 answer
  • 9. Which of the following is the<br>leading use of computer?​
    13·1 answer
  • Hey everyone. I am so bored
    14·2 answers
  • What is the core function of an enterprise platform
    12·2 answers
  • __________ is a broad class of software that is surreptitiously installed on a user's machine to intercept the interaction betwe
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!