12345678910111213141516171819202122
#include <iostream> using namespace std; long pow(int, int); main() { int x, y; cout << "Input two number x and y: "; cin >> x, y; cout << "Result of x^y is " << pow(x, y); } long pow(int x, int y) { if (y > 1) { return x * pow(x, y-1); } return x; }
cin >> x, y;
cin >> x >> y;
123456789101112131415
#include <iostream> int main() { struct pow { long long operator ()( int x, unsigned int y ) const { if ( y ) return ( x * ( *this )( x, --y ) ); else return ( 1 ); } }; std::cout << "2 ^ 4 = " << pow()( 2, 4 ) << std::endl; }