?
Solved

Raise value

Posted on 2011-02-20
8
Medium Priority
?
880 Views
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;


            system("pause");
            return 0;
}  
0
Comment
Question by:mustish1
[X]
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
8 Comments
 

Author Comment

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

        newnumber = number^25;
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34939467
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
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 400 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);
0
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!

 

Author Comment

by:mustish1
ID: 34939477
Microsoft Visual C++ 2010 Express
0
 
LVL 53

Expert Comment

by:Infinity08
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.
0
 

Author Comment

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

Accepted Solution

by:
Infinity08 earned 1600 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

0
 

Author Closing Comment

by:mustish1
ID: 34939513
Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Starting up a Project
Suggested Courses

771 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