迭代解方程

#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <time.h>
#include <algorithm>
using namespace std;

struct foo{

	char d;
};

struct s

{  int x:3;

int y:4;

int z:5;

double a;

};


#include <stdio.h>

void main()
{
	int N;
	cin >> N;
	float x= 1.0;
	float x0;
	float f;
	float f1;
	do
	{
		x0 = x;
		f = x0 * x0 - N;
		f1 = 2 * x0;
		x = x0- f/f1;

	}
	while (fabs(x -x0) >= 1e-5);
	cout << x <<endl;
}

 

posted @ 2013-09-17 15:24  l851654152  阅读(204)  评论(0编辑  收藏  举报