c programming – find maximum value in array using pointer

c programming – find maximum value in array using pointer

In this post we will show you how to find maximum value in array using pointer in c programming. flowing code will help you to perform program.

// include header file 
# include <stdio.h>
# include <conio.h>

int max(int, int *);

// main function
void main()
{
	int a[5],i,ans;
	clrscr();

	for(i=0;i<5;i++)
	{
		printf("Enter no: ");
		scanf("%d",&a[i]);
	}
	ans=max(5,a);
	printf("Maximum: %d",ans);
	getch();

}

int max(int s, int *p)
{
	int i,j,ans=*p;

	for(i=0;i<s;i++)
	  if(ans<*(p+i))
	    ans=*(p+i);

	return ans;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  19  =  23

We accept paid advance and paid guest Posting on our Site : Contact US