Write a program that uses a function to find the maximum value in an array.
C Programming Language Function in C Language (Article) Function in C Language (Program)
811Program:
#include int maximum( int [],int ); /* function prototype */ int main(void) { int values[5], i, max; printf("Enter 5 numbers\n"); for( i = 0; i < 5; ++i ) scanf("%d", &values[i] ); max = maximum( values,5 ); /* function call */ printf("\nMaximum value is %d\n", max ); return 0; } /**** function definition ****/ int maximum(int values[], int n) { int max_value, i; max_value = values[0]; for( i = 1; i < n; ++i ) if( values[i] > max_value ) max_value = values[i]; return max_value; }
Output:
Enter 5 numbers 5 6 4 2 3 Maximum value is 6
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.