"Arrange all" calculation

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
Solved it:
For all who want to know:
double sqrt = Math.Sqrt((double)numb);

int floor = (int)Math.Round(Math.Floor(sqrt));

int ceil = (int)Math.Round(Math.Ceiling(sqrt));

int[]rows = new int[floor];

int i;

for(i=0;i<floor;i++)

rows=ceil;

int diff = numb-floor*ceil;

if(diff > 0)

{

for(i=floor-1;diff-- > 0 && i>=0;i--)

{

rows++;

}

}

else if(diff <0)

{

for(i=0;diff++ < 0 && i<floor;i++)

{

rows--;

}

}



That'a all folks :)
 
Tamir Khason said:
Solved it:
For all who want to know:
double sqrt = Math.Sqrt((double)numb);

int floor = (int)Math.Round(Math.Floor(sqrt));

int ceil = (int)Math.Round(Math.Ceiling(sqrt));

Out of interest, why are you calling Math.Round here? Math.Floor and
Math.Ceiling already return whole numbers, so Math.Round shouldn't make
any odds.
 
Tamir Khason said:
Good point, I was in Java :) (there it's real double... I think in c++
too...)

What exactly do you mean? In Java Math.floor and Math.ceil still return
whole numbers - as doubles, so you'd still need to cast to int, but
even so, you still don't need the extra call.
 
Hi Tamir,

Yes, in C#, Math.Floor will return an already casted double value, so there
is no need to call Math.Round. :-)

Anyway, this is a little case, which does not matter.

If you have any further question, please feel free to post, I will help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top