C/C++编程笔记:C++的scalbn()函数,每天一个C++函数

567 阅读1分钟

所述scalbn()函数是在定义CMATH头文件。此函数用于计算给定数x与提高到幂n的FLT_RADIX的乘积。

句法:-

浮点scalbn(float x,int n);

或者

double scalbn(double x,int n);

或者

long double scalbn(long double x,int n);

或者

double scalbn(整数x,int n);

**参数:-**此方法采用两个参数:

**×:**表示有效值。

**n:**代表指数的值。

**返回值:该函数返回给定数字x和FLT_RADIX乘幂n的乘积。**在公式的帮助下:

scalbn(x,n)= x * FLT_RADIXn

下面的程序说明了上述功能:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n = 7;
    int x = 5;
    int ans;
    ans = scalbn(x, n);
    cout << x << " * "
         << FLT_RADIX << "^"
         << n << " = "
         << ans << endl;
    return 0;
}

输出:

5 * 2 ^ 7 = 640

示例2:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n = 7;
    double x = 3.9;
    int ans;
    ans = scalbn(x, n);
    cout << x << " * "
         << FLT_RADIX << "^"
         << n << " = "
         << ans << endl;
    return 0;
}

输出:

3.9 * 2 ^ 7 = 499

每天学点小知识,希望对你有帮助~

**另外如果你想更好的提升你的编程能力,学好C语言C++编程!**弯道超车,快人一步!笔者这里或许可以帮到你~

C语言C++编程学习交流QQ群【464501141】微信公众号:C语言编程学习基地

分享(源码、项目实战视频、项目笔记,基础入门教程)

欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦!