Advertisement
Guest User

Zadanie3

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package Zajecia_2;
  2.  
  3. public class Zadanie_3
  4. {
  5. public static double silnia(int k)
  6. {
  7. int tmp = 1;
  8. double silnia = 1;
  9.  
  10. for( tmp= 1; tmp<=k; tmp++)
  11. {
  12. silnia = silnia*tmp;
  13. }
  14. return silnia;
  15. }
  16. public static long potęga(int k, int x)
  17. {
  18.  
  19. int n = 1;
  20. long potęga = 1;
  21.  
  22. while (n<=k)
  23. {
  24. potęga = potęga*x;
  25. n = n + 1;
  26. }
  27. return potęga;
  28. }
  29. public static double E_X_MP(int x, int k)
  30. {
  31. double suma_1 = 1;
  32. int ilosc_wyrazow_1 = 10;
  33.  
  34. while (k <= ilosc_wyrazow_1)
  35. {
  36. suma_1 = suma_1 + potęga(x, k)/silnia(k);
  37. k = k + 1;
  38. }
  39. return suma_1;
  40. }
  41. public static double Sin_X_MP(int x, int k)
  42. {
  43. double suma_2 = 0;
  44. int ilosc_wyrazow_2 = 66;
  45.  
  46. while (k <= ilosc_wyrazow_2)
  47. {
  48. if(k%2==0)
  49. {
  50. suma_2 = suma_2 + potęga(x, 2*k+1)/silnia(2*k+1);
  51. }
  52. else
  53. {
  54. suma_2 = suma_2 - potęga(x, 2*k+1)/silnia(2*k+1);
  55. }
  56. k = k + 1;
  57. }
  58. return suma_2;
  59. }
  60. public static double Cos_X_MP(int x, int k)
  61. {
  62. double suma_3 = 1;
  63. int ilosc_wyrazow_3 = 3;
  64.  
  65. while (k <= ilosc_wyrazow_3)
  66. {
  67. if(k%2==0)
  68. {
  69. suma_3 = suma_3 + potęga(x, 2*k)/silnia(2*k);
  70. }
  71. else
  72. {
  73. suma_3 = suma_3 - potęga(x, 2*k)/silnia(2*k);
  74. }
  75. k = k + 1;
  76. }
  77. return suma_3;
  78. }
  79. public static void main(String[] args)
  80. {
  81. int x = 1;
  82. int k = 0;
  83.  
  84. System.out.println("E^x wynosi: " + E_X_MP(x, k));
  85. System.out.println("Sin(x) wynosi: " + Sin_X_MP(x, 2*k+1));
  86. System.out.println("Cos(x) wynosi: " + Cos_X_MP(x, 2*k));
  87. System.out.println("Silnia wynosi: " + silnia(k));
  88. System.out.println("Potęga wynosi: " + potęga(k,x));
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement