Thursday, July 26, 2012

Some useful Math class’s methods in C-sharp




By using Math class we can program our code easily in C#.  For example we need to find square root of 900.0

Math.Sqrt( 900.0 )

So to get 30.0 as output type:        
                                            Console.WriteLine(Math.Sqrt(900.0));

One more interesting thing is you can evaluate an expression(i.e, combination of constant variables & operators) by using this method: 

If a=13.0, b=3.0, c=4.0
Then  the statement        

                                       Console.WriteLine( Math.Sqrt( c + d * f ) );  
evaluates the square root of (13.0+3.0*4.0) = 25.0 – namely 5.0        

Now see in the figure above some more methods that uses in Math class.

Don't delay to practice the functions. Start at the right time.  

No comments:

Post a Comment