Solved

Raise value

Posted on 2011-02-20
8
874 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
  • 4
  • 3
8 Comments
 

Author Comment

by:mustish1
Comment Utility
I tried this line but it says 27 its wrong

        newnumber = number^25;
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
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 35

Assisted Solution

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

by:mustish1
Comment Utility
Microsoft Visual C++ 2010 Express
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
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
Comment Utility
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 400 total points
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
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…

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now