Smallest element in an Array using pointers

To find Smallest element in an Array using pointers.


#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,small,*ptr,arr[50];
printf("Enter the size of an array: ");
scanf("%d",&n);
printf("\nEnter the array elements: \n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
ptr = arr;
small = *ptr;
ptr++;
for(i=0;i<n;i++)
{
if(small > *ptr)
small = *ptr;
ptr++;
}
printf("\n Smallest element of the array is %d \n",small);

}


OUTPUT:



Post a Comment

0 Comments