C++ Math log10()函数

C++ Math log10()函数

该函数计算给定数字的常用算法(以10为底)。

数学上

假设一个数字为’x’:

log10x = log10(x);

语法

float log10(float x);
double log10(double x);
long double log10(long double x);
double log10(integral x);

注意:return_type可以是float、double或long double。

参数

x : 要计算其常用对数的值。

返回值

给定数字的返回值如下:

Parameter(x) Return value
x>1 Positive
x=1 0
1>x>0 Negative
x=0 -infinity
x<0 Not a Number

示例1

让我们看一个简单的示例,当x的值大于1时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=5;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 5
Log value of x is : 0.69897

在这个示例中,x的值为5。因此,函数log10()返回正值,即0.69。

示例2

让我们看一个简单的示例,当x的值等于1时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=1;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 1
Log value of x is : 0

在这个示例中,x的值是1。因此,函数log10()返回值为零。

示例3

让我们看一个简单的示例,当x的值为0.3时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=0.3;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 0.3
Log value of x is : -0.522879

在这个示例中,x的值是0.3。因此,函数log10()返回的是负值,即-0.52。

示例4

让我们看一个简单的示例,当x的值为零时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=0;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 0
Log value of x is : -inf

在这个示例中,x的值为零。因此,函数log10()返回负无穷大的值。

示例5

让我们看一个简单的示例,当x的值为-4时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x= -4;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : -4
Log value of x is : nan

在此示例中,x的值为-4。因此,函数log10()返回非数字(nan)。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程