C++ scalbn( ) function














































C++ scalbn( ) function



 scalbn( ) -

 The scalbn() functions return the value of n * (FLT_RADIX)x when successful. This   function is defined in the cmath header file, it is used to calculate the product of given   number and FLT_RADIX raised to the power xThe value of FLT_RADIX is 2 on all   machines we know of except the IBM 360 and derivatives.

 Syntax :- int scalbn(int n, int x);     or
                  float scalbn(float n, int x);   or
                  double scalbn(double n, int x);  and other data types are also types can be preferred.


 This function takes two parameters x and n where n is any value and x is the value of the exponent.
 scalbn(n, x) = n * FLT_RADIX ^ x


 Code :-
 #include<iostream>
 #include<cmath>
 #include<float.h> 
 using namespace std;

 int main() {
double n;
int x;
cout << "Enter the value of the significand : ";
cin >> n;
cout << "\nEnter the value of the exponent : ";
cin >> x;
        cout << "\n\n" ;
float ans = scalbn(n, x);
cout << n << " * " << FLT_RADIX << "^" << x << " = " << ans <<  endl;
return 0;
 }

 Output :-
 Enter the value of the significand : 4.22
 Enter the value of the exponent : 5

 4.22 * 2^5 = 135.04


Comments