Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. double power (int base, int n){
  8. int p,i;
  9. for (i = 1; i<n+1; i++){
  10. p = p*i;
  11. }
  12. return p;
  13. }
  14.  
  15. double degrees_to_rad (double x){
  16. x = x * M_PI/180;
  17. return x;
  18. }
  19.  
  20. double absolute(double paragontas){
  21. return paragontas = sqrt(power(paragontas,2));
  22. }
  23.  
  24.  
  25. int main(int argc, char *argv[]) {
  26. int i=1,l=1;
  27. double xdeg,xrad,sin1,sum=0,check;
  28. printf("Give me the x in degrees:");
  29. scanf("%lf",&xdeg);
  30. xrad = degrees_to_rad(xdeg);
  31. do{
  32. if(i==1)
  33. {
  34. sin1=power(xrad,i)/i;
  35. }
  36. else
  37. {
  38. sin1=power(xrad,i)/(i*(i-1));
  39. l=l*(-1);
  40. }
  41. check = absolute(sin1 - power(xrad,i-1)/((i-1)*(i-2)));
  42. if ( check >= 0.000001)
  43. {
  44. sum = sum + l*sin1;
  45. }
  46. i+=2;
  47. } while ( check >= 0.000001);
  48.  
  49. printf("The result using taylor series is --> %lf \n"
  50. "The result using c function sin(x) is ---> %lf",sum,sin(xrad));
  51.  
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement