Thursday, 21 June 2012

write a c program for calculate maximum & minimum number in an array



/*program for calculate maximum & minimum number in an array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,no[20],max,min;
clrscr();
printf("enter the how many number you want to enter :");
scanf("%d",&n);
printf("enter the array element :");
for(i=0;i<n;i++)
{
scanf("%d",&no[i]);
}
max=no[0];
min=no[0];
for(i=1;i<n;i++)
{
if(no[i]>max)
max=no[i];
else
if(no[i]<min)
min=no[i];
}
printf("\nthe maximum number is :%d",max);
printf("\nthe minimum number is :%d",min);
getch();
}

OUTPUT for the above code
/*enter the how many number you want to enter :4
enter the array element :1 4 3 9                                              
                                                                             
the maximum number is :9                                                      
the minimum number is :1  */

No comments: