Raise value

Posted on 2011-02-20
Last Modified: 2012-05-11
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;

            return 0;
Question by:mustish1
  • 4
  • 3

Author Comment

ID: 34939307
I tried this line but it says 27 its wrong

        newnumber = number^25;
LVL 53

Expert Comment

ID: 34939467
You're looking for the pow function in the standard C math.h header file :

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

Open in new window

LVL 35

Assisted Solution

mccarl earned 100 total points
ID: 34939470
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);
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.


Author Comment

ID: 34939477
Microsoft Visual C++ 2010 Express
LVL 53

Expert Comment

ID: 34939484
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.

Author Comment

ID: 34939492
Thanks is there any way i can do this with a 3GL logic without using pow function.
LVL 53

Accepted Solution

Infinity08 earned 400 total points
ID: 34939500
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


Author Closing Comment

ID: 34939513

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now