TheMagnusRex

Euler 5.2 modified

Jan 14th, 2021 (edited)
150
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using namespace std;
  2.  
  3. #include <iostream>
  4.  
  5. double f(double x,double y){ // ôóíêöèÿ ïåðâîé ïðîèçâîäíîé
  6.     return 5*x*x + 6*x*x;
  7. }
  8.  
  9. int main(){
  10.     double x,y,h;// x0, y0, øàã ñîîòâåòñòâåííî
  11.     int n; // êîëè÷åñòâî èòòåðàöèé
  12.     cout<<"x0=";
  13.     cin>>x;
  14.     cout<<"y0=";
  15.     cin>>y;
  16.     cout<<"h=";
  17.     cin>>h;
  18.     cout<<"n=";
  19.     cin>>n;
  20.     double yi=y;
  21.     double xi=x;
  22.     for (int i = 0;i<n;i++){
  23.         yi+= h*f(x,y);
  24.         xi+= h;
  25.         y+=0.5*h*(f(x,y)+f(xi,yi));
  26.         x+=h;
  27.     }
  28.     cout<<"x"<<n<<"="<<x<<endl;
  29.     cout<<"y"<<n<<"="<<y<<endl;
  30.     cout<<"f="<<f(x,y);
  31.     return 0;
  32. }
RAW Paste Data