Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
Syntax
1.2.
Formula
2.
Example 1
2.1.
CODE
2.2.
OUTPUT
3.
Example 2
3.1.
CODE
3.2.
OUTPUT
4.
Frequently Asked Questions
4.1.
What is scalbn() function?
4.2.
Where is the scalbn() function defined?
4.3.
What is the return value of this function?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

scalbn() function in C++

Author Ayushi Poddar
0 upvote

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:

  1. n: This represents the value of the exponent.
  2. 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

Example 2

CODE

#include <iostream>
#include <cmath>
#include <cfloat>
//header files
using namespace std;
int main ()
{
int n = 13;
double x = 3.056, answer;
answer = scalbn (x, n);
//print statement
cout << x << " * " << FLT_RADIX << "^" << n << " =  " << answer << endl;
return 0;
}

OUTPUT

3.056 * 2^13 =  25034.8

 

You practice by yourself with the help of online c++ compiler.

Must Read Dynamic Binding in C++

Frequently Asked Questions

What is scalbn() function?

Scalbn() is used to calculate the x (Product of the given number) and FLT_RADIX raised to the power n.

Where is the scalbn() function defined?

The scalbn() function is a function in C++ defined in the cmath header file.

What is the return value of this function?

This function will return the product of the given number ‘x’ and FLT_RADIX raised to the power of n.

Conclusion

This article extensively discussed the C++ Program for scalbn() function. We hope that this blog has helped you gain more knowledge regarding scalbn() and other functions, check out our articles on Coding Ninjas.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

 

Live masterclass