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
What is a reason for users and businesses to adopt 5G networks?
anzhelika [568]

Answer:

I think users and businesses needs to adopt 5g networks for primary benefits include improved bandwidth, latency, reliability, connection density and security - all important factors in the increasing move to remote working and greater reliance on online services

Explanation:

sana po nakatulong

7 0
2 years ago
Help!! Best answer will get Brainliest!!
Eddi Din [679]

Answer:

answer(s):

-set goals

-select a topic

-write down research questions

Hope this helped and sorry for the bold. <3

Explanation:

6 0
2 years ago
Read 2 more answers
How do networks help protect data? -by preventing access by more than one person at a time -by restricting access to department
Whitepunk [10]

Answer:

because they have to rest

3 0
3 years ago
Read 2 more answers
To find the ____, the net present value of the system is calculated by combining the net present value of the costs of the syste
Diano4ka-milaya [45]

Answer: c) Return on investment (ROI)

Explanation:

Return on investment (ROI)  is defined as term that measures the performance of single investment efficiency or numerous investment plans. It evaluates and assess plan of investment in form of ratio or percentage.

  • Return of investment(ROI) plan is calculated through dividing the return of investment by investment cost.
  • Other options are incorrect because cash return on capital invested ,carried forward(CF) and BI (business intelligence) are not used for calculating the investment plan through cost and benefit.Thus, the correct option is option(c)
8 0
3 years ago
Divide the difference of 47 and 23 by the difference of 25 &amp;13​
OleMash [197]

Answer:

The answer is 2

Explanation:

3 0
2 years ago
Other questions:
  • Which option should you select to ignore all tracked changes in a document
    6·1 answer
  • g Write a program to sort an array of 100,000 random elements using quicksort as follows: Sort the arrays using pivot as the mid
    7·1 answer
  • If you have two redo log groups with four members each, what’s the optimal number of disks you need to provide appropriate prote
    5·1 answer
  • Your IT manager wants you to set up three computers to appear to users as one powerful Windows Server 2016 server. What capabili
    14·1 answer
  • Explain how arrays are stored in memory? Show how arr [5] is stored in the memory. Assume each memory location is one byte long
    6·1 answer
  • Write only in C, not C++.
    14·1 answer
  • Give a recursive algorithm that takes as input a string s, removes the blank characters and reverses the string. For example, on
    7·1 answer
  • What do I do if my friend wants me to watch a video at my house?
    8·2 answers
  • Can someone help me write an algorithm and a flow chart pls for question 3
    7·1 answer
  • Look for at least ten materials tools or anything you see at home (tle)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!