| Close | Back |
/*Newton - Raphson method for calculating square roots*/
/*First sq rt program by Rajesh*/
#include <stdio.h>
#include <conio.h>
#define EPSILON 0.0001
main()
{
float n,guess;
clrscr();
printf("\n\nThis program will calculate the square root of given number\n************************************************************\n Enter zero to terminate the application");
printf("\n\n\nPlease enter a number whose root is to be found:");
scanf("%f",&n);
while(n)
{
while(n<0||n>1000)
{
printf("\nPlease enter a non zero number within 1000!");
printf("\n So what is the new number:");
scanf("%f",&n);
}
for(
guess=n/2.0;
guess * guess - n > EPSILON||guess * guess - n < -EPSILON;
guess =(guess + n/guess)/2.0
);
printf("\nThe square root of %f is %f.",n,guess);
printf("\n\nEnter a new number whose square root is to be calculated:");
scanf("%f",&n);
}
printf("\n\nThank you for using my program\n\n\n\n ---Rajesh");
getch();
}