Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bibliotecas
- import 'dart:io';
- // Principal
- void main(List<String> args) {
- // Entrada de dados
- stdout.write("# Digite N: ");
- int n = int.parse(stdin.readLineSync()!);
- // Chamada de funcao
- print("# Raiz Quadrada de $n: " + raizQuadradaNewton(n).toStringAsFixed(0));
- }
- double raizQuadradaNewton(int n) {
- double p, p_2, b = 2;
- while (true) {
- // Calculos
- p = (b + (n / b)) / 2;
- p_2 = p * p;
- b = p;
- // Condicional
- if ((-1) * (n - p_2) < 0.001) {
- return p;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement