Thursday, July 30, 2009

A c program to find biggest and smallest number in a given set of numbers?

Put the numbers into an array, and use a bubble (or exchange) sort. The first and last elements are your answer.

A c program to find biggest and smallest number in a given set of numbers?
declare int type variables like this


int i,min,max;


if variable is of int type then it can contain maximum value of 32767 and minimum value of -32766.





now u set


min=32767; and


max=-32766;


i is a variable for loop. store all the numbers in an array. suppose array has 20 values, abc[20]. then





for(i=0;i%26lt;20;i++)


{


if (abc[i]%26lt;min) min=abc[i];


if (abc[i]%26gt;max) max=abc[i];


}


when the loop is over min will contain minimum value and max xontain maximum value.
Reply:loop over the numbers and keep int min and max. Start min at the maximum value for an integer on your system and max at negitive that or zero depending on sign.





If a number is bigger than max or smaller than min set it.


When the loop is done min and max are the biggest and smallest numbers.





For most computers min should be 32767 and max should be -32766

lady palm

No comments:

Post a Comment