Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top