//Hi all ,can you explain why does this functon has two returns?
//How to read them? Is it like if/else?
int _tmain(int argc, _TCHAR* argv[])
{
int x, n;
int res;
int power(int, int);
cout << "Enter a number:";
cin >> x;
cout << "Enter a power:";
cin >> n;
res = power(x, n);
cout << "X^N is:" << res << endl;
return 0;
}
int power(int x, int n)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return power(x*x, n / 2);
return power(x*x, n / 2)*x;
}
aluhnev 0 Junior Poster in Training
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.