Introduction to the C + + algorithm race Classic Page16 exercise 1-4 sine and cosine

Source: Internet
Author: User
Tags acos cos mathematical functions sin

Title: Input positive integer n (n<360), output sine cosine of n degrees. Tip: Use Mathematical functions

The mathematical functions that need to be used:

Acos,sin,cos

Function header file: math.h

#include <math.h>

Define π:

#define PI ACOs (-1.0)

(1) Declare the positive integer variable of the input n,n the sin value of the s,n Cos value c

int N; // N: The positive integer input (n<360) double s,c; // S:n's sin value, C:n's Cos value

(2) Enter N:

scanf ("%d", &n);

(3) Seeking S and C:

S=sin ((pi*n)/d); C=cos ((pi*n)/N.);

(4) Output s,c:

printf ("%lf%lf", s,c);

Full code:

//P16 exercise 1-4 sine and cosine/*trigonometric Functions double sin (double);d ouble cos (double);d ouble tan (double);*/#include<cstdio>#include<math.h>#definePI ACOs (-1.0)//?intN//N: The positive integer input (n<360)DoubleS,c;//S:n's sin value, C:n's Cos valueintMain () {scanf ("%d",&N); S=sin ((pi*n)/ the); C=cos ((pi*n)/ the); printf ("%LF%LF", S,c); return 0;}

Introduction to the C + + algorithm race Classic Page16 exercise 1-4 sine and cosine

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.