Program to find the largest and smallest element of a 1D array
#include <stdio.h>
#include <conio.h>
void main()
{
int arr[10], i, max, min, a;
clrscr();
printf ("Enter the number of the elements of an array: ");
scanf ("%d", &a);
printf ("Enter %d elements of the array: ", a);
for ( i=0; i<a; i++ )
{
scanf ("%d", &arr[i]);
}
max = arr[0];
min = arr[0];
for ( i=1; i<a; i++ )
{
if ( arr[i]>max )
{
max = arr[i];
}
if ( arr[i]<min )
{
min = arr[i];
}
}
printf ("Largest element is %d\n", max);
printf ("Smallest element is %d", min);
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int arr[10], i, max, min, a;
clrscr();
printf ("Enter the number of the elements of an array: ");
scanf ("%d", &a);
printf ("Enter %d elements of the array: ", a);
for ( i=0; i<a; i++ )
{
scanf ("%d", &arr[i]);
}
max = arr[0];
min = arr[0];
for ( i=1; i<a; i++ )
{
if ( arr[i]>max )
{
max = arr[i];
}
if ( arr[i]<min )
{
min = arr[i];
}
}
printf ("Largest element is %d\n", max);
printf ("Smallest element is %d", min);
getch();
}