Ask Question

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

+1
Answers (1)
  1. 31 July, 04:05
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers