GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 236 of 453    Print  
How do we get Square root of any number Without using sqrt() fuction?

  
Total Answers and Comments: 3 Last Update: July 17, 2009     Asked by: rohan chapke 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 11, 2006 10:42:39   #1  
Santosh Kumar        

RE: How do we get Square root of any number Without us...

You can use a iterative method for example bisection

#include <stdio.h>
main()
{
int n;
float eval 1.0 x1 0 x2 n x; //trying to locate root between x1 0 and x2 n and giving a initial dummy value to eval
x (x1+x2)/2;
printf( Enter value for n n n );
scanf( d &n);
while((eval > 0.0001 )||( eval < -0.0001) ) { //you can change accuracy by changing 0.0001 to smaller value
eval x*x-n;
printf( eval f t eval); //printf to keep track not necessary
if(eval>0){
x2 x;
x (x2+x1)/2 ;
printf( x f t x); //printf to keep track not necessary
}
else {
x1 x ;
x (x1+x2)/2 ;
printf( x f t x); //printf to keep track not necessary
}
printf( n n );
}
printf( the root is f x);


}


 
Is this answer useful? Yes | No
August 14, 2006 05:26:53   #2  
sathish kumar        

RE: How do we get Square root of any number Without us...
#include

main()

{

int a 5;

int b a**a;

printf( d b);

}



I hope the above program would work under Unix. It is not working in Turbo C. If anything wrong in this program please let me know about that through my email.

 
Is this answer useful? Yes | No
August 21, 2006 04:10:42   #3  
Kiran        

RE: How do we get Square root of any number Without us...
#include main(){ int n;float sqr 0.000001;printf( nEnter any number );scanf( d &n);while((sqr*sqr)
 
Is this answer useful? Yes | No
December 17, 2006 03:24:25   #4  
R.S.Jayasathyanarayanan        

RE: How do we get Square root of any number Without us...
#include

main()

{

int a 5;

int b a^(.5)

tf( d b);

}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape