Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c++ program that will generate 10000 random numbers between 1 and 200,00

ID: 652225 • Letter: W

Question

Write a c++ program that will generate 10000 random numbers between 1 and 200,000. The values will be stored in an array. After that, there are specific tasks that must be done:

1. Search and print out 100 numbers that are located closest to the middle number out of the 10000 numbers that were randomly given. Show each numbers across the page followed by a "," (comma) after each number.

2. Sort the numbers in order using the Bubble Sort and print out the number of swaps in the bubble sort.

3. Sort the numbers in order using the Selection Sort and print out the number of swaps in the selection sort.

4. Sort the numbers in order using the Quick Sort and print out the number of swaps in the quick sort.

Explanation / Answer

#include<iostream.h>

using namespace std;

int main()

{

int Bswap=0;

int Sswap=0;

int Qswap=0;

int a[],b[];

cout<<"enter numbers";

for(int i=0;i<10000,i++)

{

cin>>b[i];

if(b[i]>=1 && b[i]<200000)

{

a[i]=b[i];

}

}

int closest()

{

cout<<"middle 100 numbers are";

for(int i=4950;i<5050;i++)

{

cout<<","<<a[i];

}

Bubblesort()

{

for(int i=1;i<10,000;++i)

for(j=0;j<(10000-i);++j)

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

Bswap++;

}

cout<<"Array after bubble sort: ";

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

cout<<a[i]<<" ";

cout<<"Bubble sort number of swaps are "<<Bswap;

}

int selectionsort()

{

int i,j,t;
     for(i=0;i<10000;i++)
     {
                     for(j=i+1;j<10000;j++)
                     {
                                       if(a[j]<a[i])

                                       {
                                                    tp=a[i];
                                                    a[i]=a[j];
                                                    a[j]=tp;

Sswap++;
                                       }
                     }
     }

cout<<"Array after selection sort: ";

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

cout<<a[i]<<" ";

cout<<"selection sort number of swaps are "<<Sswap;

}

cout<<"Quick sort number of swaps are "<<qswap;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote