Smallest and largest integer from the array
C program to find the smallest and largest integer from the array.
Program
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
int arr[MAX];
int i, n, max, min;
printf("Enter the number of elements in the array\t:");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
printf("Element %d\t:",i+1);
scanf("%d",&arr[i]);
}
max = arr[0];
min = arr[0];
for(i=0;i<n;i++)
{
if(arr[i] > max)
max = arr[i];
if(arr[i] < min)
min = arr[i];
}
printf("\nLargest element of the array is\t:%d",max);
printf("\nSmallest element of the array is\t:%d",min);
getch();
}
Output
Enter the number of elements in the array :8
Enter the elements
Element 1 :45
Element 2 :58
Element 3 :42
Element 4 :15
Element 5 :47
Element 6 :25
Element 7 :89
Element 8 :42
Largest element of the array is :89
Smallest element of the array is :15