#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ float g,r,c=0,n,pg;
cout<<"enter the number to find squareroot ";
cin>>n;
g=n/2; pg=n; //g - guess pg - previous guess
while(g!=pg) // when g==pg , then g or pg is the square root
{r=n/g;
pg=g;
g=(g+r)/2;
}
cout<<"square root \t"<<g<<endl;
getch();
}
For more visit
http://computersciencedora.blogspot.in
#include<conio.h>
using namespace std;
int main()
{ float g,r,c=0,n,pg;
cout<<"enter the number to find squareroot ";
cin>>n;
g=n/2; pg=n; //g - guess pg - previous guess
while(g!=pg) // when g==pg , then g or pg is the square root
{r=n/g;
pg=g;
g=(g+r)/2;
}
cout<<"square root \t"<<g<<endl;
getch();
}
For more visit
http://computersciencedora.blogspot.in
No comments:
Post a Comment