Comparing numbers and determing the biggest.

  • Thread starter Thread starter esparkman
  • Start date Start date
E

esparkman

Hey guys! 1st time poster here. Got a quick question. I'm just
beginning my journey into csharp and am developing a win32 app that
will retrieve a given useres account pull raw data from a db and
display that info. One of the things i need t odo is look at 7 entries
and compare those and then decide which is biggest and display that.
I am stuck. Can anyone help me out. I'm in no way asking for someone to

do this and me strip the code i would just like some very guided
directon. Any productive response would be awesome.
 
Not sure if there more to your problem that what a simple algorithm might
solve, but here is something that might work. I just threw it together and
so I am not sure if it will work.

public int findLargest( params int[] numSet ){
int largestFound = numSet[0];

// This can be optimized so that first element is not eval since it was
initialized above.
foreach( int num in numSet ){
largestFound = Math.Max(largestFound, num);
}

return largestFound;
}
 
this is a simple approach
i will write psudocode and hope that u can figure it all out
its extremely easy

variable currentNum = 0
variable largestFound = 0

take the very first # assign it to currentNum

while(we have more numbers)
{

if currentNum > largestFound
largestFound = currentNum
currentNum = read next number

}
 
Back
Top