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
Gre4nikov [31]
3 years ago
6

Write a program that sorts an array of 20 random numbersin the range from 0 through 1000.

Computers and Technology
1 answer:
Nuetrik [128]3 years ago
6 0

Answer:

#include<iostream>

#include<stdlib.h>

#include<time.h>

#include <algorithm>

using namespace std;

//main function program start from here

int main(){

   //seed the rand() function

   srand(time(NULL));

   //initialization

   int arr[20];

   //generate the 20 random number

  for(int i=0;i<20;i++){

   arr[i]=rand()%1000;   //store in array

  }

  sort(arr,arr+20); //sort the array by inbuilt function

  cout<<"The sorted array is."<<endl;

  //for display the each element in the array

  for(int i=0;i<20;i++){

   cout<<arr[i]<<endl;

  }

}

Explanation:

Create the main function and declare the array with size 20.

Take a for loop and generate the random number 20 times. For generating a random number, use the function rand();

rand() function which defines in the library stdlib.h, generate the random number within the range.

for example:

rand() % 20: generate the number between 0 to 19 ( Exclude 20).

for generating the random number different for every time, then we have to use srand() function and time function which defines in time.h library.

After that, store the number in the array.

Finally, take another loop and print all elements one by one.  

You might be interested in
Write a program that allows the user to enter a time in seconds and then outputs how far an object would drop if it is in free f
Sonja [21]

Answer:

// here is code inn c++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

   int t;

   double acc=32;

   cout<<"Enter the time in seconds:";

   // read the time in seconds

   cin>>t;

   // Calculate the distance=acceleration x time-squared divided by 2

   double dis=acc*(t*t)/2;

   // print the distance

   cout<<"distance is: "<<dis<<" feet."<<endl;

return 0;

}

Explanation:

Read the time in seconds from user and assign it to variable "t". declare and initialize variable "acc" with 32.Find the distance as "dis=acc*(t*t)/2". Print the distance.

Output:

Enter the time in seconds:10

distance is: 1600 feet.

6 0
3 years ago
Which disc store compacity for full lenght movie? dvd or cd
galben [10]
DVDS have a lot more available bytes for use compared to a CD. Movies are typically take up a LOT of space- so DVDS are your best option
5 0
3 years ago
Software that allows users to use and adapt it for any purpose, often allowing the public to participate in further development
Sphinxa [80]

Answer:

Open Source

Explanation:

When a developer makes something open to the public, free to edit and use how they want, they make the project open source.

4 0
2 years ago
Read 2 more answers
O novo funcionário da equipe de desenvolvimento de sistemas está aprendendo os termos mais utilizados no dia a dia da empresa. A
ratelena [41]

<span>Os insetos são insetos</span>
3 0
3 years ago
What device brocasts all data packets to other nodes on a network?
katovenus [111]
Switch/Router is Broadcast 
8 0
3 years ago
Other questions:
  • In ssl/tls, a specific set of protocols that a particular cryptographic system will use to provide protection is called a ______
    5·1 answer
  • Whats the size of a short bond paper in microsoft word?
    10·1 answer
  • Dillard’s wants to learn about its consumers' attitudes toward online purchases. There are numerous studies that are available a
    9·1 answer
  • (PYTHON HOMEWORK)Given the following code snippet, which statement tests to see if all three sets are equal?:
    11·1 answer
  • Lamp is an acronym for a complete solution of open source software that goes together to build a general purpose web server. whi
    13·1 answer
  • Which data type can store decimal or fractional numbers?
    15·2 answers
  • Overview In this assignment, you will gain more practice with designing a program. Specifically, you will create pseudocode for
    7·1 answer
  • The Power of If Worksheet
    13·2 answers
  • The Internet is a worldwide communications network. Which device connects computer networks and computer facilities?
    11·1 answer
  • Explain the measures put in place in order to maintain each of the element of computer security<br>​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!