/*****************************************************************/ // 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.esmartguy.com ( WEB MASTER ) // Group : c4swimmers@yahoogroups.com ( GROUP OWNER ) /*****************************************************************/ #include /* 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