Tuesday, August 16, 2011

Write a Program to find the square root of a given number

Write a Program to find the square root of a given number
#include
#include
float SquareRoot(float num);
void main()
{
float input, ans;
clrscr();
printf("\n Enter The Number : ");
scanf("%f", &input);
ans = SquareRoot(input);
printf("\n Square Root : %f", ans);
getch();
}

float SquareRoot(float num)
{
if(num >= 0)
{
float x = num;
int i;
for(i = 0; i < 20; i ++)
{
x = (((x * x) + num) / (2 * x));
}
return x;
}
}

No comments:

Post a Comment