Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C that declares three arrays with N elements with random values between -100 to 100. Use #define N 10 to set

Write a program in C that declares three arrays with N elements with random values between -100 to 100. Use #define N 10 to set N to an arbitrary number before the main function. The define statement, the function prototypes, and the sample main function are provided below.

I) Write a print_array2 function that prints the entires in an array of type double.

II) Write a bubble sort function that sorts the elements in ascending or descending order depending on the value of the input argument order (0=ascending and 1=descending).

III) Write an insertion sort function that sorts that numbers in an array in ascending order.

IV) Compare the runtime of the bubble sort and the insertion sort functions (no submission required).

//define N #define N 10

//function prototypes

void print_array2(double array[], int length);

void bubble_sort(double array[], int length, in order);

void insertion_sort(double array[], int length);

//sample main

void main(){

double array1[N];

double array2[N];

double array3[N];

for(int i = 0; i < N;i++){

array1[i] = rand() % 200 - 100;

array2[i] = rand() % 200 - 100;

array3[i] = rand() % 200 - 100;

}

print_array2(array1,N);

print_array2(array2,N);

print_array2(array3,N);

bubble_sort(array1,N,0);

bubble_sort(array2,N,1);

insertion_sort(array3,N);

print_array2(array1,N);

print_array2(array2,N);

print_array2(array3,N);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions