Question

In: Computer Science

Computer Science Question 1: DO NOT USE ANY NON-STANDARD LIBRARY. o All the required libraries have...

Computer Science Question 1:

DO NOT USE ANY NON-STANDARD LIBRARY. o All the required libraries have already been included. O DO NOT INCLUDE ANY OTHER LIBRARY INTO THE CODE. o DO NOT ALTER THE NAMES OF THE C FILES PROVIDED. o DO NOT ALTER THE NAMES AND PROTOTYPES OF THE FUNCTIONS.DO NOT ALTER ANY OF THE CODE! JUST ADD WHAT NEEDS TO BE ADDED FOR IT TO WORK! Please copy and paste the whole solution. Please read the code below and complete what it is asking.

This is the code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define SIZE 20

// A regular function to check and return the maximum value between two integers
int max(int a, int b);

// A recursive function for recursively find and return the maximum value in an array of integers
int maximumValue(int a[], int size);

int main(void) {

        srand(time(NULL));

        int myArray[SIZE];

        // COMPLETE THIS PART
        // ******************
        // populate the array with positive random integers less than 100





        // COMPLETE THIS PART
        // ******************
        // Print out the elements of the array in one line





        // COMPLETE THIS PART
        // ******************
        // Find and print out the maximum value in the array by calling the recursive function maximumValue



}

int max(int a, int b) {

        // COMPLETE THIS PART
        // ******************
        // if a is greater than or equal to b, return a, otherwise return b


}

int maximumValue(int a[], int size) {

        // COMPLETE THIS PART
        // ******************
        // Base case and recursive part using an if-else statement.
        // Base case:
        //              If there is only one element in the current array, return it.
        // Recursive part:
        //              Call the max function with two parameters, the first element of the array and maximumValue of the rest of the array.

Solutions

Expert Solution

Below is the solution with output screenshot

Code :

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define SIZE 20

// A regular function to check and return the maximum value between two integers
int max(int a, int b);

// A recursive function for recursively find and return the maximum value in an array of integers
int maximumValue(int a[], int size);

int main(void) {

    srand(time(NULL));

    int myArray[SIZE];

    // COMPLETE THIS PART
    // ******************
    // populate the array with positive random integers less than 100
    int r;
    for(int i=0;i<SIZE;i++)
    {
        r = rand() % 100;
        myArray[i] = r;
    }


    // COMPLETE THIS PART
    // ******************
    // Print out the elements of the array in one line
    printf("myArray = [ ");
    for(int i=0;i<SIZE;i++)
    {
        printf("%d, ",myArray[i]);
    }
    printf("]\n");


    // COMPLETE THIS PART
    // ******************
    // Find and print out the maximum value in the array by calling the recursive function maximumValue
    int max_val = maximumValue(myArray,SIZE);
    printf("\nMax Value in array is : %d",max_val);

}

int max(int a, int b) {

    // COMPLETE THIS PART
    // ******************
    // if a is greater than or equal to b, return a, otherwise return b
    if(a>b)
        return a;
    else
        return b;

}

int maximumValue(int a[], int size) {

    // COMPLETE THIS PART
    // ******************
    // Base case and recursive part using an if-else statement.
    // Base case:
    //              If there is only one element in the current array, return it.
    // Recursive part:
    //              Call the max function with two parameters, the first element of the array and maximumValue of the rest of the array.
    if(size == 1)
        return a[size-1];
    return max(a[size-1], maximumValue(a,size-1));
}

Output :


Related Solutions

Question #4 DO NOT USE ANY NON-STANDARD LIBRARY. o All the required libraries have already been...
Question #4 DO NOT USE ANY NON-STANDARD LIBRARY. o All the required libraries have already been included. O DO NOT INCLUDE ANY OTHER LIBRARY INTO THE CODE. o DO NOT ALTER THE NAMES OF THE C FILES PROVIDED. o DO NOT ALTER THE NAMES AND PROTOTYPES OF THE FUNCTIONS. DO NOT ALTER THE CODE, ONLY ADD WHATS NEEDED TO MAKE IT WORK. This is the code: #include <stdio.h> /* * This function counts and returns the number of adjacent Up...
Writ a Python Program that illustrate the DES algorithm 1-Not allowed to use any crypto libraries...
Writ a Python Program that illustrate the DES algorithm 1-Not allowed to use any crypto libraries 2- The whole algorithm must be implemented from scratch 2- The code must be properly commented Please don’t use librae’s or any code on the internet please do the code for me i have posted this many times
Writ a Python Program that illustrate the DES algorithm 1-Not allowed to use any crypto libraries...
Writ a Python Program that illustrate the DES algorithm 1-Not allowed to use any crypto libraries 2- The whole algorithm must be implemented from scratch 2- The code must be properly commented Please don’t use librae’s or any code on the internet
In question 1, do not use any properties of odd and even numbers outside of their...
In question 1, do not use any properties of odd and even numbers outside of their definitions. However, for questions 2 and 3, you can use the following parity results without having to prove them each time. For any integers a and b, the product a.b is odd if and only if a and b are both odd. For any integers, a and b, the sum a + b is even if and only if a and b have the...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do not hard code data file paths or filenames; always ask the user for them. Complete the Monster Attack project by doing the following: In place of the driver used in homework 2, add a menu with a loop and switch (this is already done, ignore this). The user must be able to add attacks, get a report on existing attacks, save a file, retrieve...
Please answer All, I do not have computer to solve. Thank you ! 1. You have...
Please answer All, I do not have computer to solve. Thank you ! 1. You have chosen biology as your college major because you would like to be a medical doctor. However, you find that the probability of being accepted to medical school is about 20 percent. If you are accepted to medical school, then your starting salary when you graduate will be $320,000 per year. However, if you are not accepted, then you would choose to work in a...
Please read the Specifications carefully. Also do not use any C library. Program Specifications Assuming that...
Please read the Specifications carefully. Also do not use any C library. Program Specifications Assuming that all input strings are non-empty (having length of at least 1) and shorter than MAX_LENGTH, implement the following string functions: • strgLen( s ): return the length of string s. • strgCopy( s, d ): copy the content of string s (source) to d (destination). • strgChangeCase( s ): for each character in the string, if it is an alphabet, reverse the case of...
QUESTION 1 This goes for ALL fill in the blank questions- Do not use Commas or...
QUESTION 1 This goes for ALL fill in the blank questions- Do not use Commas or Periods in your answers, just the letter. If not, your answer will be marked wrong. The following events took place in June 2016. Senior Frogg’s prepares monthly financial statements. Senior Frogg’s. is in the business of making Mexican Food. Match each event with the choice that correctly describes the effect of the transaction on the accounting equation: Increase (+), Decrease (-), No effect (NE)....
General guidelines: Use EXCEL or PHStat to do the necessary computer work. Do all the necessary...
General guidelines: Use EXCEL or PHStat to do the necessary computer work. Do all the necessary analysis and hypothesis test constructions, and explain completely. Read the textbook Chapter 11. Solve the textbook example on page 403, "Mobile Electronics," in order to compare four different in-store locations with respect to their average sales. Use One-Way ANOVA to analyze the data set, data, given for this homework. Use 5% level of significance. 1) Do the Levene test in order to compare the...
General guidelines: Use EXCEL or PHStat to do the necessary computer work. Do all the necessary...
General guidelines: Use EXCEL or PHStat to do the necessary computer work. Do all the necessary analysis and hypothesis test constructions, and explain completely. Read the textbook Chapter 13. Imagine that you are managing a mobile phone company. You want to construct a simple linear regression model to capture and represent the relationship between the number of customers and the annual sales level for a year with 95% confidence. You had conducted a pilot study for the past fifteen years...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT