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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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);
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 241
Problem to open text file 11 136
Select specific duplicate row based on specific criteria 4 72
Assignment from incompatible pointer type? 2 40
This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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