Solved

# Raise value

Posted on 2011-02-20
874 Views
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
Question by:mustish1
• 4
• 3

Author Comment

I tried this line but it says 27 its wrong

newnumber = number^25;
0

LVL 53

Expert Comment

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

LVL 35

Assisted Solution

mccarl earned 100 total points
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 Comment

Microsoft Visual C++ 2010 Express
0

LVL 53

Expert Comment

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 Comment

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

LVL 53

Accepted Solution

Infinity08 earned 400 total points
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 Closing Comment

Thanks.
0

## Featured Post

### Suggested Solutions

userCompare  challenge 3 61
Change to event 1 72
Math question 3 54
python sqlite question 11 42
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…