Write the mysterious function \"enigma\" into a program and test it with some va
ID: 3783372 • Letter: W
Question
Write the mysterious function "enigma" into a program and test it with some values. Try to figure out what enigma does, and why it does it. Turn in a paragraph discussing your theory on what enigma does, along with an explanation of why it does what you say. Also, answer the following question: Is enigma a "cool" function or a "stupid" function.
int enigma( int a, int b )
{
if( b == 0 )
{
return 1;
}
else
{
int x = enigma( a, b/2 );
if( b % 2 == 0 )
{
return x*x;
}
else
{
return x*x*a;
}
}
}
Explanation / Answer
Hey,I analysed enigma function.Here,is the paragraph explaining enigma function.
Paragraph:
Enigma finds the number with base a and power b. It simply gives result of ab.Reason is does is that it simply multiplying the number b times. It first divides the b/2 and allows the number a get's multiplied sqaure times.Due to which ;it literally just finds the resultant of ab.
Process:
It goes on calling the enigma function under recursion with (a,b/2) untill b=0; once b=0 it returns 1.And, then,on the stack functions return 'a' multiplied with 'a' such times.As, b/2 each time;the return value is squared in the next function.And,at the end it gives the resultant ab.
Yup,enigma is a cool function in order to find the resultant number of ab.And,instead of using pow function one can use this code also.And,it also makes good use of name "enigma" .One can't easily say that the functionality of it's function unless solved by an example
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.