C++ programming. i urgently need help in this.plz help me!

Feb 2013
31
0
Canada
Write a C++ program that uses the following function that computes xn.
 

HallsofIvy

MHF Helper
Apr 2005
20,249
7,909
That's very peculiar. Any caculator will do that easily and Windows includes a "virtual" calculator that will. So why do you need such a program?

If this is for a class in C++ programming, I would think the point would be for you to write the program!

I will tell you this much- for the actual calculation, and assuming that n is an integer, use a loop:
\*************\
func nthPower(real x; int n)
int p= 1; \* initialize p*\
for (int i= 0;i++;i< n) \* go through the loop n times*\
\** what do you think goes here? **\
return p;
\*************\

The fornat may not be exactly right. It has been a long time since I programmed in C++!

(if n is not an integer you may want to use \(\displaystyle x^n= e^{nln(x)}\))
 
Last edited:

ILikeSerena

MHF Helper
Dec 2011
734
210
Hi Riana! :)

Something like this?

Code:
#include <cmath>
#include <iostream>

using namespace std;

int main(void)
{
    double x = 2.72;
    double n = 6;
    cout << pow(x, n) << endl;
    return 0;
}
 
  • Like
Reactions: 1 person
Feb 2013
31
0
Canada
thankx everyone but later on i figured out :)