A program to find the smallest element in an array using pointer.
A program to find the smallest element in an array using pointer.
Codes
/*A program to find the smallest element in an array using pointer*/
/*Programed by Jitendra Kr Yadav
10116
2Apr,2011*/
#include<stdio.h>
#include<conio.h>
void smallest(int, int*);
main()
{
intn,a[20];
printf(“Enter the no of input to be taken:”);
scanf(“%d”,&n);
printf(“Enter the input:\n”);
for(int i=0;i<n;i++)
scanf(“%d”,&a[i]);
smallest(n,&a[0]);
printf(“Minimum =%d\n\n”,a[n-1]);
printf(“Press any key to continue…”);
getch();
}
void smallest(intx,int*num)
{
inti,temp;
for(i=0;i<x-1;i++)
if(num[i]<num[i+1])
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
}
}
Output
Enter the no of input to be taken: 5
Enter the number:
6
2
9
4
0
Minimum = 0
Press any key to continue…
Comments (1)