/*****************************************************************
* File : bigsmall.c
* Purpose : To find the biggest and smallest element in a list
* Author : Nanda Kishor K N
* Mail Id : knnkishor@yahoo.com, nandakishorkn@rediffmail.com
* Website : www.c4swimmers.net ( WEB MASTER )
* Group : c4swimmers@yahoogroups.com ( GROUP OWNER )
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License,or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****************************************************************/
#include<stdio.h>
/*
Name : main()
Purpose : This is the main function that accepts 'N' number of elements and
computes the biggest and smallest element in a list.
This does not call any other function.
Parameter : None
*/
int main()
{
// Variable Declarations & Initialization
// Naming conventions are used like all integer variables should begin with 'i'
int iIdx, iN, iA[20], iBig, iSmall;
printf("How many numbers you want to enter : ");
scanf("%d",&iN);
printf("\nEnter %d numbers : \n",iN);
for (iIdx = 0; iIdx < iN; iIdx++)
{
printf("NUMBER %d = ",iIdx+1);
scanf("%d",&iA[iIdx]);
}
// Compute the biggest and smallest among the given numbers
iBig = iA[0];
iSmall = iA[0];
for (iIdx = 1; iIdx < iN; iIdx++)
{
if (iA[iIdx] > iBig)
iBig = iA[iIdx];
if (iA[iIdx] < iSmall)
iSmall = iA[iIdx];
}
// Display the result
printf("\nThe biggest among the given numbers is %d",iBig);
printf("\nThe smallest among the given numbers is %d",iSmall);
return 0;
} // End of Program
|