Perl | sqrt() Function

Many times it happens that while solving mathematical expressions we require to calculate the square root of a number.
To solve this issue, like other programming language Perl provides us with a built-in function sqrt() which can be used to calculate the square root of a number.

Syntax: sqrt value

Returns: square root of the value passed

Note: sqrt() can only calculate square root of positive values.
 
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl
  
# Calculating square root using sqrt()
$square_root = sqrt(64);
  
# Printing the result
print "Squareroot of 64 is: $square_root";

chevron_right


Output:

Squareroot of 64 is: 8

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl
  
# Calculating square root using sqrt()
$square_root = sqrt(16);
  
# Printing the result
print "Squareroot of 16 is: $square_root";

chevron_right


Output:

Squareroot of 16 is: 4


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.