Improve company productivity with a Business Account.Sign Up

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

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
Asked:
mustish1
  • 4
  • 3
2 Solutions
 
mustish1Author Commented:
I tried this line but it says 27 its wrong

        newnumber = number^25;
0
 
Infinity08Commented:
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
 
mccarlIT 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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
mustish1Author Commented:
Microsoft Visual C++ 2010 Express
0
 
Infinity08Commented:
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
 
mustish1Author Commented:
Thanks is there any way i can do this with a 3GL logic without using pow function.
0
 
Infinity08Commented:
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
 
mustish1Author 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.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now