How the syntax of a^b=c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How the syntax of a^b=c

for example, 2^2=4 and 3^3=27 also 2^4=16 how I suppose to code that? thanks in advance

7th Apr 2017, 11:53 AM
Denny Lukman
Denny Lukman - avatar
1 Answer
+ 2
Usually, there is either case in any of programming languages: 1, There is a static Math class or library with operation methods you can use, like: c = Math.Power(a, b) 2, There is an operator for it, like: c = a ^ b If none of the above is given you are free to search on the net for "<lang name> power of number" or as the last solution, you can write a similar method as Math.Power yourself. Exact cases of 5^2: [C#] double c = Math.Pow(a, b); Console.WriteLine(Math.Pow(5, 2)); [Java] double c = Math.pow(a, b); System.out.println(Math.pow(5, 2); [Python] c = a ** b; c = math.pow(a, b); print(5 ** 2); [C++] #include <cmath> cout << pow(5, 2);
7th Apr 2017, 12:07 PM
Magyar Dávid
Magyar Dávid - avatar