/* MAXIMUM AND MINIMUM */
#include<stdio.h>
#include<conio.h>
int min,max;
void main()
{
int i,n,a[10];
clrscr();
printf("\n\t\tINPUT:");
printf("\n\t\t------");
printf("\n\t\tEnter the number of elements: ");
scanf("%d",&n);
printf("\n\t\tEnter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
min=max=a[0];
maxmin(a,n);
printf("\n\t\tOUTPUT:");
printf("\n\t\t-------");
printf("\n\t\tThe minimum value is: %d",min);
printf("\n\t\tThe maximum value is: %d",max);
getch();
}
maxmin(int a[],int n)
{
n--;
if(n==0)
return;
if(max<a[n])
max=a[n];
if(min>a[n])
min=a[n];
maxmin(a,n);
return;
}
INPUT:
------
Enter the number of elements: 5
Enter the elements:
54
334
87
34
90
OUTPUT:
-------
The minimum value is: 34
The maximum value is: 334
No comments:
Post a Comment