Programming Examples
C program to find the maximum value from array using function
Write a program which should consists of a user defined function "maximum()". Pass 1D array to the function, along with number of elements of array. Find out the maximum element in 1D array using this function.Â
Solution
#include<stdio.h>
int maximum(int*,int);
int main()
{
int num[100],n,a,max; ;
printf("How many element you want to store : ");
scanf("%d",&n);
for(a=0;a<n;a++)
{
scanf("%d",&num[a]);
}
max=maximum(num,n);
printf("The Maximum Element of array is: %d",max);
return 0;
}
int maximum(int *ptr,int n)
{
int a,max;
max=*ptr;
for(a=1;a<=n;a++)
{
if(max<*ptr)
{
max=*ptr;
}
ptr++;
}
return(max);
}
Output
How many element you want to store : 5
3
4
5
66
3
The Maximuim Element of array is: 66