Tuesday, 21 May 2013

FIND THE SQUARE ROOT OF ANY NUMBER WITHOUT USING PREDEFINED FUNCTIONS IN MATH.H



Here I have a simple C program that asks from the user a number and calculate it's square root without using any predefined function in math.h.
This program even calculates the square root to a fairly good precision of 2 digits.



Source code :-
/*******************************************************************************/
#include<stdio.h>
#include<conio.h>

int main()
{
float i,j;
float num;
j=0.0001;
clrscr();

printf("ENTER ANY NUMBER : ");
scanf("%f",&num);

for(i=0;i<num;i=i+j)
{
if((i*i)>num)
{
i=i-j;
break;
}
}
printf("%.2f",i);
getch();
return 1;
}
/*****************************************************************************/

Output :-


For finding the square root you can also use my program in C to find fractional power of any number, for details visit http://codingloverlavi.blogspot.in/2013/05/calculate-fractional-power-of-number.html
This program is very efficient and is really interesting. Please don't forget to give your valuable sugestion.

No comments:

Post a Comment