/*CSEMATTER.BLOGSPOT.IN
Program:C Program to find maximum and minimum simultaneously*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,arr[20],max,min,i,j;
clrscr();
printf("enter the no. of elemnets to be enterd");
scanf("%d",&n);
//entering data in array
printf("enter the elements");
for(i=1;i<=n;i++)
scanf("%d",&arr[i]);
// assigning last element in max and min
max=arr[1];
min=arr[1];
//comparing the elements with max and min
for(i=2;i<n;i++)
{
if(arr[i]> max)
{
max=arr[i];
}
if(arr[i]< min)
{
min=arr[i];
}
//printing the elements
printf("minimum element is %d",min);
printf("\nmaximum element is %d",max);
getch();
}
/*OUTPUT:
enter the no. of elemnts to be enterd 6
enter the elements
15 6 2 18 5 78
minimum element is 2
maximum element 78
*/
No comments:
Post a Comment