View Code of Problem 74

#include<iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cmath>
using namespace std;


int main() {
	double n;
	scanf("%lf", &n);
	double x1,x2;
	x1 = 1;
	x2 = 2;
	while (fabs(x1 - x2) >= 0.00001) {
		x1 = x2;
		x2 = (x1 + n / x1)/2;
	}
	printf("%.3lf", x2);
	return 0;
}	

Double click to view unformatted code.


Back to problem 74