Question
must be done in C
You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int si
0 0
Add a comment Improve this question Transcribed image text
Answer #1




#include <stdio.h>
int maxArray(int size, int *arr);
int main(){
int size = 10;
int arr[10] = {4, 6, 2, 1, 9, 6, 5, 9, 2, 4};
int max;
max = maxArray(size, arr);
printf("The array contains: ");
for(int i = 0; i < size; i++)
printf("%d ", arr[i]);
printf("\nMaximum: %d\n", max);
return 0;
}
int maxArray(int size, int *arr){
int max = arr[0];
for(int i = 1; i < size; i++)
{
if(arr[i] > max)
max = arr[i];
}
return max;
}

output
---
The array contains: 4 6 2 1 9 6 5 9 2 4
Maximum: 9

Add a comment
Know the answer?
Add Answer to:
must be done in C You will implement a function that matches one of the prototypes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi!, having trouble with this one, In this class we use visual studio, C++ language --------------------------------------------------------------...

    Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • You are going to implement Treesort algorithm in C++ to sort string data. Here are the...

    You are going to implement Treesort algorithm in C++ to sort string data. Here are the steps to complete the homework 1) Use the following class definition for binary search tree nodes. Its constructor is incomplete you should first complete the constructor. class TreeNode t public: string data; / this is the string stored in the node TreeNode left: TreeNode right; TreeNode (string element, TreeNode 1t, TreeNode rt //your code here 2) Write a function that will insert a string...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT