Question
// // main.cpp // Shell Sort // // NO OUTPUTTTTTTTTTTTTTTTT #include #include #include #include using namespace std; int rand(); // function to generate random number
//
// main.cpp
// Shell Sort
//
// NO OUTPUTTTTTTTTTTTTTTTT
#include
#include
#include
#include
using namespace std;
int rand(); // function to generate random number
void sort(int a [], int n); // function to sort the array
void display(int a[]); // function to display the array
int main()
{
int array[25];
srand(time(NULL)); //ERRORRRRRRRRRRRRRRRRRR
for(int i= 0; i < 20; i++)
{
array[i] = rand();
}
sort(array, 20);
display(array);
return 0;
}
int rand()
{
return(1 + rand() % 50); // return random number from 1 to 50 // ERRORRRRRRRRRRRRR
}
void sort(int a[], int n)
{
int temp;
for(int x = 0; x < n; x++)
{
for(int i = 0; i < n; i++)
{
if(a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
}
void display(int a[])
{
for(int c = 0; c < 20; c++)
{
cout << a[c] << endl;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started