#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int a; scanf("%d",&a); double x1,x2; x1=1; x2=(x1+a/x1)/2; while(fabs(x2-x1)>0.00001){ x1=x2; x2=(x1+a/x1)/2; } printf("%.3lf\n",x2); return 0; } |
Double click to view unformatted code.