Created
May 9, 2013 11:15
-
-
Save gmfc/5546904 to your computer and use it in GitHub Desktop.
Metodo de Newton para raiz quadrada.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| class prog{ | |
| public static void main(String [] args){ | |
| double xa,n,eps,xn; | |
| Scanner s = new Scanner(System.in); | |
| xa = s.nextDouble(); | |
| n = s.nextDouble(); | |
| eps = s.nextDouble(); | |
| xn = xa - (xa*xa-n)/(2*xa); | |
| while(math.abs(xn-xa)>=eps){ | |
| xa = xn; | |
| xn = xa -(xa*xa-n)/(2*xa); | |
| } | |
| system.out.println(xn); | |
| }//main | |
| }//prog |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Da para otimizar o código com um único loop for.