31 October 2015

Finding Squre Root


/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict:
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
in data ;
double finding_sqrt()
{
    double e = 0.000001 ;
    double x = data ;
    double y =1 ;
    while(x-y>e)
    {
        x = (x+y) /2 ;
        y = data/x ;
    }
    return x ;
}

int main()
{
    while(sc("%d",&data)==1)
    {
    double sqt = finding_sqrt() ;
    pf("%.2lf\n\n",sqt) ;

    }

    return 0 ;
}

No comments:

Post a Comment

UVA 10679 - I Love Strings!!