Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created August 9, 2014 13:45
Show Gist options
  • Save keizo042/6f99e1a978ebbb5de23d to your computer and use it in GitHub Desktop.
Save keizo042/6f99e1a978ebbb5de23d to your computer and use it in GitHub Desktop.
newton法、美しいアルゴリズム
#include<stdio.h>
#include<stdlib.h>
double newton(double c)
{
double x;
int i;
x = ( c + c / c ) / 2;
for(i=0;i < 1000000; i++)
{
x = ( x + c /x ) / 2;
}
return x;
}
int
main(int argc, char **argv)
{
double c =2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2-1,
t;
t = newton(c);
printf("%10.100lf\n",t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment