x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 883

# 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;
}
0
mustish1
• 4
• 3
2 Solutions

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

newnumber = number^25;
0

Commented:
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);
``````
0

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

Author Commented:
Microsoft Visual C++ 2010 Express
0

Commented:
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

Author Commented:
Thanks is there any way i can do this with a 3GL logic without using pow function.
0

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;
``````
0

Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.