This is a user defined program to print the square root of a number. It is supposed to work for numbers which aren't perfect squares as well. i
is incremented by a step of 0.01
each time and the the value of i*i
is checked if equal to n
. And if equal then the value of i
is printed.
#include <stdio.h>
void squareRoot(double);
int main()
{
double num;
scanf("%lf", &num);
squareRoot(num);
return 0;
}
void squareRoot(double n)
{
double i;
for (i = 0; i < n; i += 0.01)
{
//printf("%.2lf\n",i*i);
if (i * i == n)
{
printf("%lf\n", i);
break;
}
}
}