Thursday, 21 December 2017

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:



No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...