Ask Question
13 November, 09:50

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

+3
Answers (1)
  1. 13 November, 10:07
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers