rfq

cos

rfq
Feb 2nd, 2023 (edited)
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3.  
  4. int faktorial(int N)
  5. {
  6.     if (N==0) return 1;
  7.     else return N*faktorial(N-1);
  8. }
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.  
  15.     ///MENGERJAKAN SOAL cos MCLaurin
  16.     double zigma = 0.;
  17.     double x = 0.5;
  18.     int N = 5;
  19.     double y = cos(0.5);
  20.     double galat;
  21.     for (int i = 0; i<=N; i++)
  22.     {
  23.         zigma = zigma + (pow(-1,i)*pow(x,2*i+1)/faktorial(2*i+1));
  24.         galat = y - zigma;
  25.         // cout<<zigma<<endl;
  26.         printf("Sigma: %.20f\nGalat: %.20f\n", zigma, galat);
  27.         // cout<<galat<<endl;
  28.     }
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment