Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem you will write multiple functions IN C LANGUAGE that operate on one or multiple arrays. Write the implementations for the five prototype

In this problem you will write multiple functions IN C LANGUAGE that operate on one or multiple arrays. Write the implementations for the five prototype functions specified below. Call the functions from the sample main that is provided below.

I) Write a function void print_array(int array[], int length) that takes an array and the length of the array as the input arguments. The function is required to print the array to screen with a space between each number and a new line character after the last entry.

II) Write a function int first_index(int array[], int length, int x) that returns the index of the first entry equal to x in the array. The function should return -1 if the value x does not exist in the array.

III) Write a function int num_occurrences(int array[], int length, int x) that returns the number of occurrences of the value x in the array.

V) Create a function bool compare_arrays(int array1[], int array2[], int length) that compares two arrays of the same length and returns a bool indicating if the two arrays are identical or not. You need to include the line #include at the top of your program to have access to the bool data type.

//prototype of functions

void print_array(int array[], int length);

int first_index(int array[], int length, int x);

int num_occurrences(int array[], int length, int x);

bool compare_arrays(int array1[], int array2[], int length);

//sample main

void main(){

printf("Problem 3 ");

int A[10] = {1,2,3,3,3,4,5,6,7,8};

int B[10] = {1,2,3,10,3,4,5,6,7,8};

print_array(A,10);

int index1 = first_index(A,10,3);

int index2 = first_index(A,10,10);

printf("index1: %d index2: %d ",index1,index2);

int count1 = num_occurrences(A,10,1);

int count2 = num_occurrences(A,10,3);

printf("occurrences1: %d occurrences2: %d ",count1,count2);

bool equal1 = compare_arrays(A,A,10);

// ? is similar to an if statement

(equal1) ? printf("Equal! ") : printf("Not equal!");

bool equal2 = compare_arrays(A,B,10);

(equal2) ? printf("Equal! ") : printf("Not equal!");

}

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 Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago