×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

sin() function with example in C++

C++ sin() function: Here, we are going to learn about the sin() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 27, 2019

C++ sin() function

sin() function is a library function of cmath header, it is used to find the sine of the given number (angle), it accepts a number (x) and returns the sine of angle x radians.

Syntax

Syntax of sin() function:

sin(x);

Parameter(s)

x – is the value of an angle in radians whose sine to be calculated.

Return value

double – it returns double type value that is the sine of given angle x radians.

Sample Input and Output

Input:
float x = 2.45;
    
Function call:
sin(x);    
    
Output:
0.637765

Example

// C++ code to demonstrate the example of 
// sin() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    x = -10.23;
    cout<<"sin("<<x<<"): "<<sin(x)<<endl;

    x = 0;
    cout<<"sin("<<x<<"): "<<sin(x)<<endl;    

    x = 2.45;
    cout<<"sin("<<x<<"): "<<sin(x)<<endl;    
    
    return 0;
}

Output

sin(-10.23): 0.720984
sin(0): 0
sin(2.45): 0.637765

Reference: C++ sin() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.