codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <math.h> #include <stdio.h> int main() { double x = 0; double y = 0; double y_1; long i; while(1) { printf("Enter x : "); if(!scanf("%lf",&x) || getchar() != '\n') { while(getchar() != '\n'){} printf("bad input\n"); } else { if((y_1 = x) != 0) { i = 0; do { y = y_1; y_1 = y + (y - pow(y,4.0)/x)/3; printf("Iteration %d\n", (i = i + 1)); printf("y = %lf\t error = %lf\n", y_1, fabs(y_1 - y)); } while(2*pow(10.0,-6.0) < fabs(y_1 - y)); } printf("answer : %lf\n",y_1); } } return 0; }
Private
[
?
]
Run code
Submit