Instruction
1
The simplest case occurs when the number should be built in a small whole positive degree. This mathematical operation can be done in literally one line. For example, if the number should always be elevated to the fourth degree, use this line:b:=a*a*a*a;write a and b must be of a type appropriate to the range and type of number under construction in the degree.
2
If the number is also elevated to a whole and positive degree, but it is large, and, moreover, can change, use cycle. To do this, place in the program fragment like this:c:=a;if b=0 then c:=1;if b>=2 then for i:=2 to b do c:=a*c;Here a is the number to be elevated to the degree, b is the exponent, c is the result. The variables i and b are necessarily of type integer.
3
To raise a number to a fractional degree, use the properties of logarithms. The corresponding program fragment will look like this:c:=exp(b*ln(a));This method does not allow to work with zero and negative numbers. To resolve the first of these disadvantages, use of such a structure:if a=0 then c:=1 else c:=exp(b*ln(a));This will allow you to bypass the limitation on the range of values of the input parameter of the natural logarithm, which, if zero has no mathematical meaning. The second drawback, however, will remain in force to build the degree of a negative number still fail. Use all variables of type real.
4
To build in a degree of a negative number, take its module, substitute in the previous expression, then change the sign of the result. In Pascal it would look as follows:c:=(-1)*exp(b*ln(abs(a)));Then, if the degree is even, take the modulus from the result:if round(b/2)=b/2 then c:=abs(c);
5
Sometimes there is a need for a universal piece of software that allows the construction of degree in any numbers. Then compile it as follows:c:=0;if a0 then c:=exp(b*ln(a));if b=0 then c:=1;if round(b/2)=b/2 then c:=abs(c);Here all variables are also of type real.