Calculate a square and a square root!
C and C++, 68 65 bytes
#include<math.h>
float f(float n){auto p=.5;return pow(n,2-p*3);}
Original answer:
#include<math.h>
float f(float n){return pow(n,sizeof('-')-1?2:.5);}
For both versions, C produces n^2
and C++ produces sqrt(n)
.
Python 2 & Python 3, 23 21 bytes
lambda n:n**(1/2or 2)
Python 2.x produces n^2
, Python 3.x produces sqrt(n)
.
2 bytes saved thanks to @Dennis!
Jolf and MATL, 1 byte
U
Square root in Jolf, square in MATL.
Try it online! (MATL)
Try the Jolf code. Only works on Firefox.
These are both 1 byte, as MATL and Jolf both use ASCII/extended ASCII codepages, so all commands are 1 byte.