Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<float.h>
  4. #define PI 3.141592
  5.  
  6. int factorial(int num){
  7. int sum = 1;
  8. for (int i = 0; i < num; i++) {
  9. sum = sum * (i + 1);
  10. }
  11. return sum;
  12. }
  13.  
  14. float nax(float num, float x){
  15. float ret=1.0;
  16. for(int i=1;i<=x;i++){
  17. ret=ret*num;
  18. }
  19. return ret;
  20. }
  21.  
  22.  
  23. float sine(float uhol, float epsilon){
  24. while (uhol >= 180) {
  25. uhol = uhol - 180;
  26. }
  27.  
  28. while (uhol <= -180) {
  29. uhol = uhol + 180;
  30. }
  31.  
  32. if(uhol > 90){
  33. uhol = uhol - 2*(uhol - 90);
  34. }
  35.  
  36. if(uhol < -90){
  37. uhol = uhol - 2*(uhol + 90);
  38. }
  39.  
  40. int i = 0;
  41. double osszeg = 0;
  42. double szin = 0;
  43. double hasonlito;
  44. int elojel;
  45. do {
  46. elojel = nax(-1, (i));
  47. osszeg = elojel * nax(uhol * PI / 180, (2 * i + 1)) / factorial(2 * i + 1);
  48. hasonlito = osszeg;
  49. szin = szin + osszeg;
  50. i++;
  51. } while (((osszeg > epsilon) || (-osszeg > epsilon)) && (((osszeg - hasonlito) > epsilon) || ((osszeg - hasonlito) < epsilon)));
  52. return szin;
  53. }
  54.  
  55. int main(){
  56. int uhol;
  57. float epsilon;
  58. scanf("%d %f",&uhol,&epsilon);
  59. for (int i=-360;i<360;i+=10){
  60. printf("Enyem:(%d) %f\n",i,sine(i,epsilon));
  61. printf("Rendes: %f\n",sin(i*PI/180));
  62. }
  63.  
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement