Question one hundred and thirty-nine: Functions cos () and sin ()

Source: Internet
Author: User

[Plain] # include <stdio. h>
# Include <stdlib. h>
# Include <math. h>
 
# Define PI 3.1415926
 
Int factorial (int num );
Double COS (double x );
Double SIN (double x );
 
Int main ()
{
Double x;

Printf ("Please enter the Angle:"); // the Angle required by the input
Scanf ("% lf", & x );

Printf ("sin (x * PI/180) = % lf \ n", SIN (x * PI/180 ));
Printf ("cos (x * PI/180) = % lf \ n", COS (x * PI/180 ));

System ("PAUSE ");
Return 0;
}
 
// The definition of the function
 
// ** Factorial function
Int factorial (int num)
{
Int sum;

Sum = 0;
If (num = 0 | num = 1)
{
Sum = 1;
}
Else
{
Sum = num * factorial (num-1 );
}

Return sum;
}
 
// ** Sin () function
Double SIN (double x)
{
Int I;
Int k;
Double sum;

K = 1;
Sums = 0.0;

For (I = 1; pow (x, I)/factorial (I)> 0.0000001; I + = 2)
{
Sum + = k * pow (x, I)/factorial (I );
K =-1 * k;
}

Return sum;
}
 
// ** Cos () function
Double COS (double x)
{
Int I;
Int k;
Double sum;

K = 1;
Sums = 0.0;

For (I = 0; pow (x, I)/factorial (I)> 0.0000001; I + = 2)
{
Sum + = k * pow (x, I)/factorial (I );
K =-1 * k;
}

Return sum;
}

# Include <stdio. h>
# Include <stdlib. h>
# Include <math. h>

# Define PI 3.1415926

Int factorial (int num );
Double COS (double x );
Double SIN (double x );

Int main ()
{
Double x;

Printf ("Please enter the Angle:"); // the Angle required by the input
Scanf ("% lf", & x );

Printf ("sin (x * PI/180) = % lf \ n", SIN (x * PI/180 ));
Printf ("cos (x * PI/180) = % lf \ n", COS (x * PI/180 ));

System ("PAUSE ");
Return 0;
}

// The definition of the function

// ** Factorial function
Int factorial (int num)
{
Int sum;

Sum = 0;
If (num = 0 | num = 1)
{
Sum = 1;
}
Else
{
Sum = num * factorial (num-1 );
}

Return sum;
}

// ** Sin () function
Double SIN (double x)
{
Int I;
Int k;
Double sum;

K = 1;
Sums = 0.0;

For (I = 1; pow (x, I)/factorial (I)> 0.0000001; I + = 2)
{
Sum + = k * pow (x, I)/factorial (I );
K =-1 * k;
}

Return sum;
}

// ** Cos () function
Double COS (double x)
{
Int I;
Int k;
Double sum;

K = 1;
Sums = 0.0;

For (I = 0; pow (x, I)/factorial (I)> 0.0000001; I + = 2)
{
Sum + = k * pow (x, I)/factorial (I );
K =-1 * k;
}

Return sum;
}

 

 
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.