Arkanium77

Задача 1

Apr 22nd, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. Задача 1. Работает как-то не совсем правильно. Ну, или я с проверкой что-то напутал.
  2. #include <cmath>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <string>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. double Arctg1(double x, double E,int n){
  12.     int zn, s;
  13.     double sum,res,xx;
  14.     sum=0;
  15.     s=1;
  16.     while (s<=n){
  17.         if((s-1)%2==0) zn=1;
  18.         else zn=-1;
  19.         xx=1;
  20.         for (int i=1;i<=(2*s-2);i++){
  21.                 xx*=x;
  22.         }
  23.         res=(zn*xx)/(2*s+1);
  24.         if (abs(res)>E)sum+=res;
  25.         s+=1;
  26.     }
  27.     return sum;
  28. }
  29.  
  30.  
  31. int main(){
  32.     srand(time(0));
  33.     setlocale(0,"");
  34.     double x,E;
  35.     int n;
  36.     x:
  37.     cout<<"Введите X:"<<endl;
  38.     cin>>x;
  39.     cout<<endl<<"Введите N:"<<endl;
  40.     cin>>n;
  41.     if((abs(x)<1)&&(n>=1)){
  42.         for(int i=1;i<=6;i++){
  43.             cout<<"Введите Эпсилон:"<<endl;
  44.             cin>>E;
  45.             cout<<endl<<"Arctg="<<Arctg1(x,E,n)<<endl<<endl;
  46.             cout<<endl<<"Проверка! Arctg = "<<atan(x)<<endl;
  47.         }
  48.     }
  49.  
  50.     cout<<endl<<endl<<"Если хотите повторить - введите 1"<<endl;
  51.      cin>>n;
  52.     if (n==1) {system("cls"); /*system("clean");*/ goto x;}
  53. }
Advertisement
Add Comment
Please, Sign In to add comment