#include<stdio.h>
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;
}
Enter 5 numbers
5
6
4
2
3
Maximum value is 6
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.