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
4. Name and fix the two errors in the following piece of code that is intended to print “Debugging is fun!”. print //(“Debugging
umka2103 [35]
<span>print //(“Debugging is fun!”)


Here the print is a function and // is a parameter that is used to comment section of the code. Any function call must be followed by argument call, which in case here is commented. So, the bug arises. So the correct code will be:

</span>print (“Debugging is fun!”)
3 0
3 years ago
4. What is the package name in which the Scanner class resides?
Ahat [919]
Related Articles. Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings.
7 0
3 years ago
Which of the following software programs provides for e-mail communication?
Mila [183]
Outlook is a software program that provides for e-mail communication
8 0
3 years ago
Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number
kolbaska11 [484]

Answer:

C++ program explained below for the problem

Explanation:

// UpComingMarathon.cpp : Defines the entry point for the console application.

//header files

#include "stdafx.h" //optional

#include <iostream>

#include <cstring>

#include <fstream>

#include <iomanip>

using namespace std;

//declare the gobal array of type double

double average[5];

//declare the function prototypes

void getData(ifstream& inf, string n[], double runData[][8], int count);

void calculateAverage(double runData[][8], int count);

void print(string n[], double runData[][8], int count);

int main()

{

   string names[5];

   double runningData[5][8];

   ifstream inputfile("input.txt");

   if(inputfile)

   {

        //call the method getData

        getData(inputfile, names, runningData, 5);

   }

   else

   {

        //error message

        cout<<"Sorry! Unable to open the file."<<endl;

        system("pause");

        return 0;

   }

   //close the file

   inputfile.close();

   //call the method calculateAverage to compute the

   //average miliage of each runner

   calculateAverage(runningData, 5);

   //call display the names and their weekly run rate and their averages

   print(names, runningData, 5);

   system("pause");

   return 0;

}

//definition of method getData that reads the data from the file and

//stores the names into array n and run data into runData array

//simultaneously.

void getData(ifstream& inf, string n[], double runData[][8], int count)

{  

   while(!inf.eof())

   {

        for(int i=0;i<count; i++)

        {

            inf>>n[i];

            for(int j=0;j<7;j++)

            {

                inf>>runData[i][j];

            }

        }

   }

}

//definition of method calculateAverage that comptes the total first

//then stores the value of average into the average array

void calculateAverage(double runData[][8], int count)

{

   double total;

   for(int i=0;i<count;i++)

   {

        total=0;

        for(int j=0;j<7;j++)

        {

            total+=runData[i][j];

        }        

        average[i]=total/7;      

   }

}

//definition of method print that prints the output

//in a tabular format

void print(string n[], double runData[][8], int count)

{

   cout<<setfill('=')<<setw(80)<<"=";

   cout<<setfill(' ');

   cout<<endl;

   cout<<"Name"<<setw(6)<<"";

   for(int i=0;i<7;i++)

        cout<<setw(7)<<"Day "<<(i+1);

   cout<<setw(12)<<"Average"<<endl;

   cout<<setfill('=')<<setw(80)<<"=";

   cout<<setfill(' ')<<endl;

   for(int i=0;i<count;i++)

   {

        cout<<n[i]<<setw(8)<<fixed<<"";

        for(int j=0;j<7; j++)

        {

            cout<<setprecision(2)<<fixed<<runData[i][j]<<setw(3)<<"";

        }

        cout<<setw(8)<<average[i];

        cout<<endl;

   }

   cout<<setfill('=')<<setw(80)<<"=";

   cout<<endl;

}

5 0
3 years ago
Marisa wants to customize her computer's default firmware. ROM allows data to be changed or modified when necessary.
ludmilkaskok [199]

Answer: ROM stands for "Read-only memory", this is permanent, so false.

4 0
2 years ago
Read 2 more answers
Other questions:
  • g The reciprocal Fibonacci constant ψ is defined by the infinite sum: ψ=∑n=1 [infinity] 1 Fn Where Fn are the Fibonacci numbers
    7·1 answer
  • “Artificial intelligence is the tool of education in the near future”. Research on the possibility of “AI technology” in scienti
    15·1 answer
  • When registering online for your classes you log onto to a website provided by your university. The computer and web browser tha
    6·2 answers
  • You are the network adminstrator for your company your network consists of two active directory domains research.westsim.local a
    12·1 answer
  • Full form of DVX please answer fast ​
    9·1 answer
  • Why is the term RAW image file generally used to describe a variety of file formats, which are sometimes known as digital raw ca
    13·1 answer
  • write a program that asks the user how far they ran and then how long they ran and prints out their speed in miles per hour java
    15·1 answer
  • What are the advantages of using ICT jn our society?​
    8·2 answers
  • BRAINLIEST TO RIGHT ANSWER!! TIMED QUIZ HELP ASAP PLS!!
    5·1 answer
  • Five real world objects with similar characteristics​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!