/* =============================================================================================
Wilfredo Cruz Yarlequé wcruzy@gmail.com
Piura, Perú, Enero 27 de 2025
=============================================================================================
Método de Newton para calcular la raíz cuadrada de un número positivo
============================================================================================= */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
float y, error;
float g, h, m;
int k=0;
do
{
printf("Ingrese valor positivo: ");
scanf("%f", &y);
} while (y <= 0);
printf("Ingrese valor del error: ");
scanf("%f", &error);
g = 1.0;
while (k == 0)
{
h = y / g;
m = (g + h) / 2.0;
if (abs(g-h) < error)
{
printf("\n%f\n\n", m);
k = 1;
}
else
g = m;
}
}