who can help me on solvin this problem in c++ by not using math.h only a function;
problem:x^n

Recommended Answers

All 3 Replies

#include<iostream>
using namespace std;
double power(int x,int n)
{
    int power=1;
    for(int count=1;count<=n;count++)
        power=power*x;
    return power;
}
int main()
{
    int a; int b;
    cout<<"enter the base :";
    cin>>a;
    cout<<"enter the exp :";
    cin>>b;
    cout<<a<<"^"<<b<<"="<<power(a,b)
    return 0;
}   

rose_2: While your enthusiasm for answering the question is commendable, it is generally considered a poor practice to provide outright answers to problems when the OP hasn't demonstrated that they had already made a good-faith effort to solve the problem before posting here - it encourages cheating, or at least a lack of effort, and does little to actually help the students learn to program.

This can be a fine line at times - one I and most of the other regulars have inadvertently crossed at one time or another - but this particular instance is clear-cut: the OP basically posted their problem set without any indication that they had done any work on it themselves, for an assignment that shouldn't have required more than a token effort to solve.

gencc: Seriously, you needed to even consider this? You probably could have done it yourself in less time than it took to post the question, and yet you felt you needed to beg for a hand-out? This is a sign of a student who belongs in a different major, or maybe out of college entirely. If I knew who your professor was, I would e-mail them a link to this thread straight away and let the consequences fall on you for your lack of academic honesty.

deleted for duplicate post

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.