Square Root of a Number
To find the square root of a given number, import the dart:math package, call sqrt() function, and pass the number as argument to sqrt() function. sqrt() function returns a positive square root of the given number.
Dart Program
In the following program, we read a number into x
, find its square root using sqrt()
function.
main.dart
import 'dart:io'; import 'dart:math'; void main(){ //read number from user print('Enter x'); var x = double.parse(stdin.readLineSync()!); var output = sqrt(x); print('sqrt(x) = $output'); }
Output
Enter x 16 sqrt(x) = 4.0
ADVERTISEMENT
Summary
In this Dart Tutorial, we learned how to find the square root of a given number.