C# - Math.Log() Method with Example

In this tutorial, we will learn about the C# Math.Log() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 29, 2023

C# Math.Log() Method

The Math.Log() method is used to get the logarithm of a specified number with a given base. This method is overload two times. If we pass a single parameter then it will return the logarithm of the given number using base e. if we pass two parameters then the first parameter is used for number and the second parameter is for the base.

Syntax

double Math.Log(double number);
double Math.Log(double number, double base);

Parameter(s)

  • number: The number whose logarithm is to be found.
  • base: The base of the logarithm.

Return Value

It returns the logarithm of a given number.

C# Example of Math.Log() Method

The source code to demonstrate the use of Log() method of Math class is given below. The given program is compiled and executed successfully.

using System;

class Sample {
  //Entry point of Program
  static public void Main() {
    double logarithm1 = 0.0;
    double logarithm2 = 0.0;

    //Here we get logarithm of base e for 90. 
    logarithm1 = Math.Log(90);

    //Here we get logarithm of base 10 for 90.
    logarithm2 = Math.Log(90, 10);

    Console.WriteLine("Logarithm of Base E:  " + logarithm1);
    Console.WriteLine("Logarithm of Base 10: " + logarithm2);
  }
}

Output

Logarithm of Base E:  4.49980967033027
Logarithm of Base 10: 1.95424250943932
Press any key to continue . . .

C# Math Class Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.