Ask Question
27 October, 07:52

Write a function that returns the largest value stored in anarray-of-int. Test the function in a simpleprogram.

+1
Answers (1)
  1. 27 October, 11:12
    0
    C program for finding the largest Value in array of integers

    #include

    /*Function that returns the largest value stored in an array-of-int*/

    int max (int array[], int m)

    {

    int i;

    / * Initializing variable maximum with array[0]*/

    int maximum = array[0];

    / * Traversing array elements from 2 to last and comparing it with variable maximum*/

    for (i = 1; i < m; i++)

    if (array[i] > maximum)

    maximum = array[i];

    return maximum; / /returning maximum element of array

    }

    //driver function

    int main ()

    {

    int array[] = {5, 78, 23, 65, 9}; / /Input array

    int m = sizeof (array) / sizeof (array[0]); / /finding the length of array

    printf ("Largest in given array is %d", max (array, m)); /*function calling and printing maximum element of array * /

    return 0;

    }

    Output:

    Largest in given array is 78
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function that returns the largest value stored in anarray-of-int. Test the function in a simpleprogram. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers