What's Here?
- Members: 118,589
- Replies: 434,915
- Topics: 67,216
- Snippets: 2,407
- Tutorials: 642
- Total Online: 814
- Members: 63
- Guests: 751
Who's Online?
|
Welcome to Dream.In.Code |
|
|
Getting C++ Help is Easy!
Join 118,589 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 814 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
This code shows how to find out the square root of a number without using the sqrt() function. The result obtained by both functions are the same and hence can also be used as an alternative sqrt() function.
|
Submitted By: born2c0de
|
|
Rating:
 
|
|
Views: 28,079 |
Language: C++
|
|
Last Modified: August 20, 2005 |
Snippet
/* Code written by Sanchit Karve
A.K.A born2c0de
Contact Me at born2c0de AT hotmail.com
20 August, 2005
*/
#include <iostream>
#include <math.h>
using namespace std;
float sqroot(float m)
{
float i=0;
float x1,x2;
while( (i*i) <= m )
i+=0.1;
x1=i;
for(int j=0;j<10;j++)
{
x2=m;
x2/=x1;
x2+=x1;
x2/=2;
x1=x2;
}
return x2;
}
int main()
{
cout<<"Enter a Number:";
int no;
cin>>no;
cout<<"Square Root using sqroot()= "<<sqroot(no)<<endl
<<"Square Root using sqrt() = "<<sqrt(no);
return 0;
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|