Raise value

Hi guys: Can any one please tell me how to i raise the number 2 upto the 25th power and assign it to the double variable ? Thanks.

#include <iostream>
using namespace std;

int main()
{
      int number = 2;
        double newnumber = 0.00;


            system("pause");
            return 0;
}  
mustish1Asked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
If you are asking whether there is a built-in operator that does this, then no. The standard way of doing it, is by using the pow function.


If you are specifically asking about powers of 2, you could use the left-shift operator, but that has a very limited field of application obviously :
uint32_t result = 0x1 << 25;

Open in new window

0
 
mustish1Author Commented:
I tried this line but it says 27 its wrong

        newnumber = number^25;
0
 
Infinity08Commented:
You're looking for the pow function in the standard C math.h header file :

        http://cplusplus.com/reference/clibrary/cmath/pow/

For example :
double result = pow(2.0, 25.0);

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mccarlConnect With a Mentor IT Business Systems Analyst / Software DeveloperCommented:
I am guessing from the code you are using C or C++, but what environment are you using? (Linux, Windows, and Visual C, .NET, Borland, etc)

But anyway, you might have some function that you can call like...  double newnumber = pow(2, 25);
0
 
mustish1Author Commented:
Microsoft Visual C++ 2010 Express
0
 
Infinity08Commented:
The IDE you use doesn't make a difference. The pow function is in the standard C library, and is available in any standards compliant C or C++ compiler. See the reference page in my first post for more information.
0
 
mustish1Author Commented:
Thanks is there any way i can do this with a 3GL logic without using pow function.
0
 
mustish1Author Commented:
Thanks.
0
All Courses

From novice to tech pro — start learning today.