Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming not C++ C programming not C++ C programming not C++ a) Crate a file homework_part_1.c b) Crate a function initialize_array that receives two

C programming not C++

C programming not C++

C programming not C++

a) Crate a file homework_part_1.c

b) Crate a function initialize_array that receives two parameters: an array of integers and the array size. (Use pointers to pass an array of integers as parameter) Use a for loop and an if statement to put 5s in the odd positions of the array and 0s in the even positions.

c) Crate a function print_array that receives as parameters an array of integers and the array size. (Use pointers to pass an array of integers as parameter) Use a for statements to print all the elements in the array.

d) Crate a function selection_sort that receives as parameters an array of integers and the array size and order the array element in descending order. (Use pointers to pass an array of integers as parameter) Implement Selection Sort algorithm. It should be Selection Sort, not Bubble Sort, not Quick Sort, etc.

e) Crate a recursive function that calculate and returns the factorial of a number. The function receives the number (integer number) as parameter.

f) Copy the following main function in your class,

int main() {

int a [10] = {3, 5, 6, 8, 12, 13, 16, 17, 18, 20};

int b [6]= {18, 16, 19, 3 ,14, 6};

int c [5]= {5, 2, 4, 3, 1};

// testing initialize_array

print_array(a, 10); // print: 3, 5, 6, 8, 12, 13, 16, 17, 18, 20

selection_sort(a, 10);

print_array(a, 10); // print: 0, 5, 0, 5, 0, 5, 0, 5, 0, 5

// testing initialize_array

print_array(b, 6); // print: 18, 16, 19, 3 ,14, 6

selection_sort (b, 6);

print_array(b, 6); // print: 19, 18, 16, 14, 6, 3

// testing factorial

printf("Factorail of 5 - %d ", factorial (5)); //print: 120

c[0] = factorial (c[0]);

c[1] = factorial (c[2]);

print_array(c, 5); // print: 120, 24, 4, 3, 1

return 0;

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions