Quipex

Laba_3.6_II

Oct 6th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. // Laba_3.6_II_var.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <math.h>
  8. using namespace std;
  9.  
  10. long double fact(int N)
  11. {
  12.     if(N<0)
  13.         return 0;
  14.     if (N==0)
  15.         return 1;
  16.     else
  17.         return N*fact(N-1);
  18. }
  19.  
  20. int main()
  21. {
  22.     double a,b,y,s,x,h,p;
  23.     int n;
  24.     cout<<"Vvedite a, b, n:\n";
  25.     cin>>a>>b>>n;
  26.     h=(b-a)/10;
  27.     x=a;
  28.     int i;
  29.     do
  30.     {
  31.         s=0;
  32.         for(i=0;i<=n;i++)
  33.         {
  34.             p=pow(x,2*i)/fact(2*i);
  35.             s+=p;
  36.             //cout<<s;
  37.         }
  38.         y=(exp(x)+exp(-x))/2;
  39.         x+=h;
  40.         cout<<setw(15)<<s<<setw(15)<<y<<endl;
  41.     }
  42.     while(x<b);
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment