Finding Maximum number in Array using POINTER.
Following C Program is created to find maximum number in array using pointer.
C++ PROGRAM :)
using namespace std;
#include<stdlib.h>
int main()
{
int *a;
int j,n,max;
cout<<" Enter size of array: ";
cin>>n;
a = (int*) malloc(n * sizeof(int));
cout<<" Enter "<<n<<" elements in array: "<<endl;
for(j=0;j<n;j++)
{
cin>>*(a+j);
}
max = *(a+0);//Imp set max = *(a+0) not set max = *(a+j)
for(j=0;j<n;j++)
{
if(max >= *(a+j))
{
max = max;
}
else
{
max = *(a+j);
}
}
cout<<endl<<"Maximum number in array is = "<<max<<endl;
free(a);
return 0;
0 Comments