Home / Programs / Write a program that uses a function to find the maximum value in an array.
🚀 Programming Example

Write a program that uses a function to find the maximum value in an array.

👁 909 Views
💻 Practical Program
📘 Step Learning
Write a program that uses a function to find the maximum value in an array.

💻 Program Code

 #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;
}
 
                        

🖥 Program Output

Enter 5 numbers
5
6
4
2
3

Maximum value is 6

 
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.