:
F1 = 1, F2 = 1, Fi = Fi-1 + Fi-2.
Fi, Fi-1 Fi-2 F1, F2 F3.
, , 1, F2 F3, : F1 = F2; F2 = F3; F3 = F1 + F2. .
c , , .
#include<iostream>
#include <math.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
//
if(SetConsoleCP(1251)==0
{
cerr<<"Fialed to set codepage!"<<endl; // ,
}
if(SetConsoleOutputCP(1251)==0) //
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
long a, b, f1, f2 = 1, f3 = 1;
cout<< " \n";
cin>> a >> b;
cout<< " :\n";
while (f2 <= b) // ,
{
if (f2 >= a) cout<< f2 << " ";
// ,
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
cout<< endl;
_getch();
return 0;
}
5. , , :
y1 y2, eps.
x/2, : y1 y2, 2 . y1 y2 , . , : |y1-y2| < , : | | <= .
#include<iostream>
#include <math.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
//
if(SetConsoleCP(1251)==0
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)//
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
double x, eps;
//
do
{
cout<< " x >= 0 ";
cin>> x;
} while (x < 0);
do
{
cout<< " > 0 <1 ";
cin>> eps;
} while (eps <= 0 || eps >= 1);
// , :
double y1, y2=x/2;
do
{
y1 = y2;
y2 = y1 + (x/y1 - y1) / 2;
} while (fabs(y2-y1)>=eps);
cout<< " "<< y2 << endl;
|
|
cout<< " " << sqrt(x) << endl;
_getch();
return 0;
}
6. ,
.
n! n .
s, () sl. s sl , .
:
, z = 1, 2, 3 , . , .
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
using namespace std;
int main()
{
setlocale(LC_ALL,"rus_rus.1251");
//!!!
double e, sl=1, s=1, z=1,x;
cout<<" x ";
cin>>x;
do
{
cout << " > 0 ";
cin >> e;
} while (e <= 0);
// :
/* : | s l | <= , */
do
{
sl = sl*x*x / z; //
s += sl; //
z += 1; // z 1
} while (fabs(sl) >= e);
// , : | s l | <= ,
// .
do
{
sl = sl*x*x / z; //
s += sl; //
z += 1; // z 1
} while (fabs(sl) >= e);
k | |
0.001 | |
0.01 | |
0.1 | |
// (k - ),
// = 0.001,
// . k : // 1, : 10 , k // 1, :
int k=0;
while (e < 1)
{
e*=10; ++k;
}
// setprecision(),
//
// <iomanip>
cout<< " = " << setprecision(k+1) << s << endl;
cout<< " : " << exp(x*x)<<endl; _getch();
return 0;
}
7. , .
x , : n, . for, .
#include <iostream>
#include <iomanip>
#include <math.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
|
|
}
long double s = 1, sl = 1;
long double n;
cout<<" ";
cin>>n;
// :
for (long double i =1; i <= n; i++)
{
sl /= i;
/* */
s += sl;
}
cout<<"=" << setprecision(16) << s;
cout<<"\n e=" << exp(1.0) << endl;
_getch();
return 0;
}