Saturday, May 22, 2010

Please help about programing. Find the biggest element in a given array. Can someone program this in c++?

And write the code here, or send it on email.

Please help about programing. Find the biggest element in a given array. Can someone program this in c++?
if you don't do the homework, you'll never pass the test.





Im not writing your code for you but heres the logic:





declare a variable for the "greatest number" and initialize it to 0 (or -10000000) if you're array has negative numbers





use a for loop to go through each element in the array


check to see if that array element is greater then the "greatest number"





If it is, then make the "greatest number" = to that element's value





when the loop is done, "greatest number" will be equal to the biggest element in the array


thats it


go code, and dont be so lazy
Reply:Try Planet Source Code (Here's 275 examples...)


http://www.planetsourcecode.com/vb/scrip...
Reply:Several of your class mates posted the same question. I will give you an algorithm.





Remember that arrays in C++ count from zero.





Assume that the first element (element[0]) is the biggest. Set a variable called max to store this value.





For each element i in the array starting at 1


{


if element[i] is greater than max


then set max to element[i]


}


Now variable max contains the biggest value in your array.


No comments:

Post a Comment