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
Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Lorico [155]

Answer:

#here is code in Python.

#read the value n from user

n=int(input("enter the value of n:"))

#variable to store the total sum

sum_n=0

for i in range(1,n+1):

# find the sum of series

   sum_n=sum_n+1/i

#print the sum

print("sum of the series is: ",sum_n)

Explanation:

Read the value of n from user. Create and initialize a variable sum_n with 0. Run a for loop to calculate sum.Initially sum_n is 0, then for value of i=1  1/i will be added to the sum_n.Then in next iteration for i=1, 1/2 added to sum_n. Similarly loop will run util i equals to n.Then sum_n will store the sum of the

series.

Output:

enter the value of n:5

sum of the series is:  2.283333333333333

3 0
3 years ago
______________ is a raw fact about a person or an object
inessss [21]
I think its C information. Sowwy if I’m wrong
4 0
3 years ago
How do you paste a picture? or a picture link?<br><br>nvm i found out, but have some free points.
Rom4ik [11]

Answer:

Right click the picture and click copy then go to wherever you want to put it then right click there and press paste.

For the link just go to the url and highlight the entire url copy and paste that.

Explanation:

3 0
3 years ago
Read 2 more answers
This is your code.
Sever21 [200]

Construct d

  • d=[[5,10,15],[2,4,6],[11,33,55]]

So

d[2] is c i.e [11,33,55]

d[2][1]=c[1]

So it's 33

3 0
2 years ago
Local-area network (LAN) A It interconnects locations scattered throughout a metropolitan area. 2 Wide-area network (WAN) B It i
Sunny_sXe [5.5K]

Answer:

Local-area network (LAN - It interconnects network components within a local region

Metropolitan-area network (MAN)- It interconnects locations scattered throughout a metropolitan area

Wide-area network (WAN) -  It interconnects network components that are geographically dispersed between two locations.

Personal-area network (PAN) -  It is a network whose scale is even smaller than a LAN. An example of this type of network is a connection between a PC and a digital camera via a universal serial bus

Explanation:

Local-area network (LAN - It interconnects network components within a local region, it is smaller compared to a WAN

Metropolitan-area network (MAN)- It interconnects locations scattered throughout a metropolitan area

Wide-area network (WAN) -  It interconnects network components that are geographically dispersed between two locations.it uses routers to link between the geographical locations

Personal-area network (PAN) -  It is a network whose scale is even smaller than a LAN. An example of this type of network is a connection between a PC and a digital camera via a universal serial bus

8 0
3 years ago
Other questions:
  • Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment v
    5·1 answer
  • Which event most led to a reduction in the size and cost of computers? a. invention of the Bessemer converter b. development of
    8·2 answers
  • Which function returns a valid value without any arguments?
    13·2 answers
  • You have a small company and want to keep your cost low, but it is important your employees share data. which network would prov
    13·1 answer
  • In one to two sentences, explain why citizens pay taxes
    8·1 answer
  • Which deployment tool will you use to deploy metadata from one organization to another organization?
    6·1 answer
  • Select the correct answer.
    13·2 answers
  • What can always be seen in the styles gallery??
    12·1 answer
  • Rebbeca has finished with the research and outline portion of her slide presentation. Now, the next logical step is to begin wor
    11·1 answer
  • (b) A mouse is a display device. (c) A monitor is a television.​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!