C Program to find the largest and smallest number in an array.
Largest and Smallest number in an Array :
SmallLargeElements.c
#include<stdio.h>
int main(void)
{
int i,int_arr[10]={6,4,5,0,2,-1,10,-5,15,9};
int small,large;
small=large=int_arr[0];
for(i=1; i<10; i++)
{
if(int_arr[i] < small)
small=int_arr[i];
if(int_arr[i] > large)
large=int_arr[i];
}
printf("Smallest Element : = %d\nLargest Element : = %d\n",small,large);
return 0;
}
Output:
Terminal
Smallest Element : = -5
Largest Element : = 15
Happy Learning 🙂