Write a Python Program to find the square root of a number by Newton’s Method. 


Program Algorithm:
1. Define a function named newtonSqrt().
2. Initialize approx as 0.5*n and better as 0.5*(approx.+n/approx.)
3. Use a while loop with a condition better!=approx to perform the following,
i. Set approx.=better
ii. Better=0.5*(approx.+n/approx.)
4. Print the value of approx 

Program Code:
def newtonSqrt(n):
 approx = 0.5 * n
 better = 0.5 * (approx + n/approx)
 while better != approx:
 approx = better
 better = 0.5 * (approx + n/approx)
 return approx
print('The square root is' ,newtonSqrt(81)) 



Program Output :
The square root is 9 
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: