View Code of Problem 74

#include<iostream>
#include <stdio.h>
#include <string.h>
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;
}	
/*
Main.cc: In function 'int main()':
Main.cc:13:21: error: 'fabs' was not declared in this scope
  while (fabs(x1 - x2) >= 0.00001) {
                     ^
*/

Double click to view unformatted code.


Back to problem 74