Skip to content

Instantly share code, notes, and snippets.

@GaProgMan
Created January 20, 2013 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaProgMan/4578131 to your computer and use it in GitHub Desktop.
Save GaProgMan/4578131 to your computer and use it in GitHub Desktop.
An un-optimized algorithm for searching through a list of integers to find the sum of the largest and smallest values.
int n, smallest, biggest, sum, difference = 0;
for ( int i = 0; i ++; i < listOfNumbers.Count ) {
n = lisOfNumbers[i];
if ( n > biggest ) {
biggest = n;
}
else if ( n < smallest ) {
smallest = n;
}
}
sum = biggest + smallest;
difference = sum - biggest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment