Site icon Codeforcoding

log function in C programming language

log function in C programming language

In this tutorial, we will discuss log function in the C programming language

Description

In the C programming language, the log() Arithmetic function returns the logarithm of x to the based of e

log(): In C programming Language,log()  is used to perform  calculate natural logarithm of significant value

Declaration

The Syntax of the log()  in C Programming language

double log(double x);

Parameters or Arguments

X is the parameter or argument of this function which is used in the calculation of the logarithm of x to the base of e

Returns

The log function returns the logarithm of x to the base of e

Required Header

In this Language, the required header file for log()  is

#include<math.h>

log function in C

Example

The following example shows the usage of the log()

Program 1

 

#include <stdio.h>
#include <math.h>

int main()
{
    double a=1.5,b=1.25;
    printf("log value of %f is: %f\n",a,log(a));
    printf("log value of %f is: %f\n",b,log(b));
    getch();
    return 0;
}

 

When above program me  is compiled it will produce the following result

log value of 1.500000 is: 0.405465

log value of 1.250000 is: 0.223144

 

program 2

#include <stdio.h>
#include <math.h>

int main()
{   //define the variable
    double logValue;
    double inputValue;
    //get input from user
    printf("Please enter the value to calculate log value :");
    scanf("%lf",&inputValue);
    //calculate the log value
    logValue=log(inputValue);
    //display the log value
     printf("\nlog value of %lf is %lf\n",inputValue,logValue);
    getch();
    return 0;
}

When above program me  is compiled it will produce the following result

please enter the value to calculate log value :1.5
log value of 1.500000 is 0.405465

 

Other C programming language functions that are  similar to the cosine function      

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

sqrt function in C language

pow function in C language

exp function in C language

trunc function in C language

 

 

suggested for you

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

log10 Arithmetic function in C Language
String function in C programming Language
Exit mobile version