Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by P. Semeniak ( 15 years ago )
// lab10.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
double a=0.3;

double f( double x)
{
 return exp(x-a)-sqrt(x+1);
}

int _tmain(int argc, _TCHAR* argv[])
{
 //10.1.1
 double b=0.7, e=pow(10.,-6.), x;
 int i=1;
 setlocale(LC_ALL, "russian");
 cout<<"Промежуточные результаты выводятся окрyгленно!\n\n";
 while(1)
 {
  x=(a+b)/2;
  cout<<setw(5)<<setprecision(3)<<a<<" "<<setw(5)<<setprecision(3)<<x<<" "<<setw(8)<<setprecision(3)<<f(x)<<" "<<setw(2)<<i<<endl;
  if(!f(x))
  {
   cout<<endl<<"x="<<x;
   return 0;
  }
  if(f(x)*f(a)<=0)
  {
   b=x;
  }else
  {
   a=x;
  }
  if(fabs(a-b)<=2*e)
  {
   cout<<endl<<"x="<<x;
   return 0;
  }
  i++;

 }

}

 

Revise this Paste

Parent: 42357
Your Name: Code Language: