Hello, i need to make program which can do squaring, so x^n. I can do it with pow(x,n):
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x, c;
int n;
cout << "Alap = "; cin >> x;
cout << "Kitevo = "; cin >> n;
if (n < 0)
{
cerr << "Csak termeszetes szam lehet a kitevo!" << endl;
return -1;
}
c = pow(x,n);
cout << "Hatvanyertek = " << c;
return 0;
}
But i need to do it without pow(,) and only with #include <iostream>. So i need to do x*x*...*x with n times... I think i need to use a while loop but i have no idea how. Can anybody help me? (sorry for bad English)