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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz