# Ruby | Integer sqrt() function

The sqrt() function in Ruby returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n

Syntax: Integer.sqrt(number)

Parameter: The function takes the integer whose square root is to be returned. It throws an error “out of domain” if a negative number is passed.

Return Value: The function returns the integer square root.

Example 1:

 `#Ruby program for sqrt() function ` ` `  `#Initializing the number ` `num1 = 25 num2 = 16 num3 = 100 num4 = 5 ` ` `  `#Prints the sqrt of a number ` `                                      ``puts` `Integer.``sqrt``(num1) ` `                                          ``puts` `Integer.``sqrt``(num2) ` `                                              ``puts` `Integer.``sqrt``(num3) ` `                                                  ``puts` `Integer.``sqrt``(num4) `

Output:

```5
4
10
2
```

Example 2:

 `#Ruby program for sqrt() function ` ` `  `#Initializing the number ` `num1 = 64 num2 = 81 num3 = 49 num4 = 36 ` ` `  `#Prints the sqrt of a number ` `                                     ``puts` `Integer.``sqrt``(num1) ` `                                         ``puts` `Integer.``sqrt``(num2) ` `                                             ``puts` `Integer.``sqrt``(num3) ` `                                                 ``puts` `Integer.``sqrt``(num4) `

Output:

```8
9
7
6
```

My Personal Notes arrow_drop_up The function of education is to teach one to think intensively and to think critically

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 :

Be the First to upvote.

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