Saturday 23 April 2011

Write a C program to find both the larges and smallest number in a list of integers.


main( )
{
int largest(float a[ ], int n);
int value[6] = {2,45,1,2,3,67};
printf(" The largest %d\n", largest(value,6));
printf(" smallest integer : %d\n",smallest(value,6));
}
int largest(int a[], int n)
{
int i;
int max;
max = a[0];
for(i = 1; i < n; i++)
if(max < a[i])
max = a[i];
return(max);
}
int smallest(int b[],int n)
{
int i;
int min;
min=a[0];
for(i = 1; i < n; i++)
if(min > a[i])
min=a[i];
return(min);

}
/*
The largest 67
smallest integer : 1
*/

No comments:

Post a Comment