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
Compare computer virus and worm ​
Zina [86]

Answer:

You can say they're somewhat alike, since a worm wiggles into a tight spot, just like how a computer virus wiggles into your computer-

Hope this helps-

7 0
3 years ago
Read 2 more answers
Donna is a graphic designer working on a poster for a music concert. What is her objective?
Marina86 [1]

Answer:her objetive is to impress the public with the poster.

Explanation:

The poster have to be about the music. It is very important for the singer or the festival.

The objetive is going on with the festival, with the music and with the concert’s style.

It’s a personal design. But it have to be original for every design.

3 0
2 years ago
Read 2 more answers
1. Write a program that declares an array named alpha with 50 components of the type double. Initialize the array so that the fi
Aleksandr [31]

Answer:

Explanation:

1. Write a program that declares an array named alpha with 50 components of the type double. Initialize the array so that the first 25 components are equal to the square of the counter (or index) variable and the last 25 components are equal to three times the index variable.  

  double alpha[50];

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

   {

       alpha[i]=i*i;

       alpha[i+25]=(i+25)*3;

  }

2. Output the array so that exactly ten elements per line are printed.  

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

   {

       cout<<i+1<<". "<<alpha[i]<<" ";

       if (((i+1)%10)==0)

       {

           cout<<endl;

       }

   }

3. Run your program again, but this time change the code so that the array is filled with random numbers between 1 and 100.  

   double alpha[50];

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

   {

       alpha[i]=rand()%101;

   }

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

   {

       cout<<i+1<<". "<<alpha[i]<<" ";

       if (((i+1)%10)==0)

       {

           cout<<endl;

       }

   }

4. Write the code that computes and prints the average of elements of the array.  

   double alpha[50],temp=0;

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

   {

       alpha[i]=rand()%101;

       temp+=alpha[i];

   }

   cout<<"Average :"<<(temp/50);

5. Write the code that that prints out how many of the elements are EXACTLY equal to 100.

   double alpha[50],temp=0;

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

   {

       alpha[i]=rand()%101;

       if(alpha[i]==100)

       {

           temp++;

       }

   }

   cout<<"Elements Exacctly 100 :"<<temp;

Please note:  If you put  each of above code to the place below comment  it will run perfectly after compiling

#include <iostream>

using namespace std;

int main()

{

   // If you put  each of above code here it will run perfectly after compiling

   return 0;

}

8 0
2 years ago
What is the answers please
Gre4nikov [31]
which question are u referring too
6 0
3 years ago
Which statement must be included in a program in order touse a deque container?
dedylja [7]

Answer:

d.#include deque

Explanation:

We have to include deque library in order to use a deque container and the syntax to include is #include<deque>.Deque is a double ended queue which is a sequence container and allows operations of contraction and expansion on both ends of the queue.Double ended queues are a special case of simple queue since in simple queue the insertion is from rear end and deletion is from front end but in deque insertion and deletion is possible at both ends rear and front.

3 0
3 years ago
Other questions:
  • What is the difference between a switch's physical interface and the vlan interface?
    10·2 answers
  • Which devices are often used inside of tablets to store data on these devices?
    15·1 answer
  • What are some beginning keyboarding questions?
    10·2 answers
  • This is the most flexible way to create a query. Used to create queries that displays only the records that match criteria enter
    12·1 answer
  • Front wheel drive vehicles typically use​
    5·1 answer
  • Dedicated server hosting and dedicated web dedicated is the same ??????
    14·1 answer
  • What games do you play?<br><br><br> Be sure not to report any answers!
    5·1 answer
  • For what purposes do students collect data? Check all that apply.
    7·2 answers
  • Give me 5 examples of Cyber Security
    9·1 answer
  • what impact of information communication technology have on the environment about electronic waste, use of electricity?​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!