Smallest number.
Find the smallest number in an array using pointers.
#include
#include
void main(void)
{
clrscr();
int arr[10],i,*fp;
printf("\nEnter the numbers to be compared(Not more than 10)");
for(i=0;i<10;i++)
{
printf("\nEnter the %d element",i+1);
scanf("%d",&arr[i]);
}
*fp=arr[0];
for(i=0;i<10;i++)
{
if(*fp>arr[i])
{
*fp=arr[i];
}
}
printf("\n%d is the smallest value",*fp);
getch();
}
#include
#include
void main(void)
{
clrscr();
int arr[10],i,*fp;
printf("\nEnter the numbers to be compared(Not more than 10)");
for(i=0;i<10;i++)
{
printf("\nEnter the %d element",i+1);
scanf("%d",&arr[i]);
}
*fp=arr[0];
for(i=0;i<10;i++)
{
if(*fp>arr[i])
{
*fp=arr[i];
}
}
printf("\n%d is the smallest value",*fp);
getch();
}
Comments
Post a Comment