Write a program which will input some numbers in an integer array and pass this to a function called maximum (). This function will find the maximum of the array values and returns this value to the main () function for displaying it

#include <stdio.h>
#include <conio.h>

int maximum( int [] );        

int  maximum( int values[5] )
{
    int  max_value, i;
       
    max_value = values[0];
    for( i = 0; i < 5; ++i )
        if( values[i] > max_value )
            max_value = values[i];
       
    return max_value;
}
   
main()
{
    int values[5], i, max;
   
    printf("Enter 5 numbers\n");
    for( i = 0; i < 5; ++i )
        scanf("%d", &values[i] );
       
    max = maximum( values );
    printf("\nMaximum value is %d\n", max );
    getch();
}
Next Post Previous Post
No Comment
Add Comment
comment url