Introduction
The scalbn() function is a function in C++ defined in the cmath header file. And hence as the name suggests, scalbn() is used to calculate the x (Product of the given number) and FLT_RADIX raised to the power n. FLT_RADIX(use <cfloat> header file) as mentioned is the value of the radix (integer base) of the exponent representation. This kind of method takes two parameters which are:
- n: This represents the value of the exponent.
- x: This represents the value of significand.
Syntax
double scalbn(double x, int n);
long double scalbn(long double x, int n);
double scalbn(integral x, int n);
float scalbn(float x, int n);
Formula
scalbn(x, n) = x * FLT_RADIXn
Return Value: This function will return the product of the given number ‘x’ and FLT_RADIX raised to the power of n.
Also see, Literals in C, Fibonacci Series in C++
Example 1
CODE
#include <bits/stdc++.h>
#include <cmath>
#include <cfloat>
//header files
using namespace std;
int main()
{
int n = 7;
int x = 5;
int ans;
answer = scalbn(x, n);
cout << x << " * "<< FLT_RADIX << "^"
<< n << " = "
<< answer << endl;
return 0;
}
OUTPUT
5 * 2^7 = 640
Also Read - C++ Interview Questions