Hey I am pretty new to c++ and algorithmic , so please try explaining me what to do or give me a code for example don't redirect me to a site that already made a library for this because you only wasted your time telling me that.
For example i want to calculate 25 ^ 7 .
For a low number it works as :

cin>>a>>b;
                    for(i=1;i<=b;i++){
                                answer=answer*a;
                                 }

But i need a to make a program that works for 0<a,b<100.
Please Help me. I tried a lot of ideas but all failed

Recommended Answers

All 11 Replies

>try explaining me what to do or give me a code for example
You could look at any of the open source libraries that do what you want for ideas on how to write your own implementation.

>don't redirect me to a site that already made a library for
>this because you only wasted your time telling me that

With your attitude, I think telling you what to do or giving you example code would be more of a waste of time. I try not to give proper help to people who don't deserve it.

commented: unfortunatly they wont +1

don't redirect me to a site that already made a library for this because you only wasted your time telling me that.

Here's some redirection for you: show effort

I'm feeling generous, so I'll give you a little hint.
Use doubles.

Bla bla bla

Where do you people come from?

I'm honestly curious. There are so many people with horrible grammar and atrocious attitudes floating around the various coding sites that demand code from people.

Where do you people come from?

I'm honestly curious. There are so many people with horrible grammar and atrocious attitudes floating around the various coding sites that demand code from people.

I DEMAND CODE FROM YOU!!!!
No seriously, I have wondered about the same question before.

These are the posts that scare me about asking for coding help...haha.

These are the posts that scare me about asking for coding help...haha.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{

double a,b,answer;

cin>>a>>b;

answer=pow(a,b);

cout<< answer;

return 0;

}

Edit: Not even going to bother. Suffice to say, Gnarlyskim - you're just reinforcing negative behaviour.

Hmm yes valid point, however I think the others prior to me reinforced the idea that acting like a jerk isn't a good idea.

That is one example of a way to solve an exponent. Who is to say that this is what he or she needed exactly. Chances are extremely slim.

I'm a student in my first C++ class and I've learned primarily through trial and error and help from other people from forums. My first few codes were mostly written by other people, but I had to adapt and learn the language (or little of what I know) because of the fact that no one is going to sit down and write a long code because you don't want to. If anything, this code helped me as a practice, so I don't mind supplying it to him. If he takes this little code and researches and plays around with it, then I've succeeded.


Now all this being said, Robby14, attempt to phrase your question in a manner than won't anger people...

Edit: Not even going to bother. Suffice to say, Gnarlyskim - you're just reinforcing negative behaviour.

he did say "please" in his topic title ;) haha.

But at least he posted SOMETHING for code. There has been worse, even on the limited time I've been on this site.

If the result is too big,it may overflow,because the variable has a fixed length.
Exactly,you can use arrays to store every digit of the result,and at last,calculate the real value again

#include<iostream>
#include<cmath>
using namespace std;

int main()
{

double a,b,answer;

cin>>a>>b;

answer=pow(a,b);

cout<< answer;

return 0;

}

Double number may have 64bits length,so it has a limit on the stored value(minus 32 times, 32 times)

Double number may have 64bits length,so it has a limit on the stored value(minus 32 times, 32 times)

There is a limit, but I'd be surprised if the OP would have to worry about going larger than 1.7 * 10 ^308.

Of, course, with the big numbers you lose precision in lesser significant digits, but usually with large numbers, nobody cares about that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.