C Program to Find Maximum Number in an Array Using Function

C Program / Source Code:

Here is the source code of the C program to find the maximum or largest number in an array.
/* Aim: Write a C program to find the maximum or largest number in an array. */ 

#include<stdio.h>

int Maxarr(int arr[],int n); // Maxarr Function Prototype 

void main()
{
	int i,arr[5],num;

	printf("\n Enter array elements(Max 5 elements):- ");
 
	for(i=0;i<=4;i++)
		scanf("%d",&arr[i]);

	printf("\n Enter any number:- ");
	scanf("%d",&num);

	printf("\n The maximum number in the given array is %d \n \n",Maxarr(arr,num));
 
} // End of main() function

 // Maxarr Function to find maximum or largest number in an array
int Maxarr(int arr[],int n)
{
	int i,max;
	max=arr[0];
	for(i=0;i<=n;i++)
	{
		if(max<arr[i])
		max=arr[i];
	}
 
	return max;
}

/* Output of above code:-

 Enter array elements(Max 5 elements):- 40 45 60 68 100

 Enter any number:- 5

 The maximum number in the given array is 100
*/