Program To Evaluate Square Root Of A Number
Program To Evaluate Square Root Of A Number :-
#include<stdio.h>
#include<conio.h>
void main()
{
float a,q,b,i;
clrscr();
printf("Enter Any Number : ");
scanf("%f",&q);
a=b=q/2;
for(i=0;i<50;i++)
{
b=((a+(q/b))/2);
a=b;
}
printf("The Square Root Of %f Is -> %f",q,b);
getch();
}
#include<conio.h>
void main()
{
float a,q,b,i;
clrscr();
printf("Enter Any Number : ");
scanf("%f",&q);
a=b=q/2;
for(i=0;i<50;i++)
{
b=((a+(q/b))/2);
a=b;
}
printf("The Square Root Of %f Is -> %f",q,b);
getch();
}
THIS EVALUATION IS BASED ON BABYLONIAN METHOD
Square roots by Divide-and-Average
This method dating back to the Babylonians (1700 B.C.) is known as the Babylonian Algorithm.
If A > 0 is a guess of the square root of the positive number Q, then a better approximation to √Q is given by
B = (A + Q/A)/2.
Now you use B as an approximation and compute C = (B + Q/B)/2, and so on to get as close as you want to the value of √Q. We have shown elsewhere why the Babylonian Algorithm works.
This method dating back to the Babylonians (1700 B.C.) is known as the Babylonian Algorithm.
If A > 0 is a guess of the square root of the positive number Q, then a better approximation to √Q is given by
B = (A + Q/A)/2.
Now you use B as an approximation and compute C = (B + Q/B)/2, and so on to get as close as you want to the value of √Q. We have shown elsewhere why the Babylonian Algorithm works.
Example:
Let us find the square root of 5. Let A = 2.
Then B = (2 + 5/2)/2 = 2.25
C = (B + Q/B)/2 = (2.25 + 5/2.25)/2 = (2.25 + 2.22)/2 = 2.235
Notice that this value is getting closer with each iteration to the actual value 2.2360679...
Let us find the square root of 5. Let A = 2.
Then B = (2 + 5/2)/2 = 2.25
C = (B + Q/B)/2 = (2.25 + 5/2.25)/2 = (2.25 + 2.22)/2 = 2.235
Notice that this value is getting closer with each iteration to the actual value 2.2360679...
You might wonder how one might even think of Q/A in connection with finding the square root of Q.
Well, if A were indeed the square root of Q, then A2 = Q and so A = Q/A.
And even if A is not the square root of Q so that A ¹
Q/A, it turns out that
√Q lies strictly between A and Q/A, and their average B produces a
shorter interval from B to Q/B within which √Q still lies and the
average of B and Q/B produces an even shorter interval containing √Q,
and so on.
!!! HOPE U LIKE IT !!!
!!! THANKS FOR READING !!!
!!!!!HAPPY PROGRAMMING !!!!!
!!!!!HAPPY PROGRAMMING !!!!!
U Can catch me at http://www.facebook.com/salokr
gud one bro..
ReplyDeleteThanx Buddy :D
Delete