In this tutorial, we will discuss cos function in C programming language
Description of cos() Arithmetic function in C programming language
The cos() in C programming language returns the cosine of the radian angle x.
cos() : In the C Programming Language,the cos() is used to calculate cosine value .
The declaration of the cos() in C programming language is
double cos(double x);
the parameter of cos is:
x – it is floating point value is used for angle as the parameter of this function. It is always measured in radians.
The cos function returns cosine value of x, measured in radians
The required header of the cos() is
#include <math.h>
following example shows the usage of the cosine function.
Program 1
#include <stdio.h> #include <stdlib.h> int main() { double x=0.5; double y=1.0; printf("cosine value of %f is %f\n",x,cos(x)); printf("cosine value of %f is %f\n",y,cos(y)); getch(); return 0; }
When the above program is compiled and run, it will produce the following results.
cosine value of 0.500000 is: 0.877583 cosine value of 1.000000 is: 0.540302
Program 2
#include <stdio.h> #include <math.h> int main() { //define the variable double cosineValue; double inputValue; //get input from user printf("Please enter the value to calculate cosine value :"); scanf("%lf",&inputValue); //calculate the cosine value cosineValue=cos(inputValue); //display the cosine value printf("\ncosine value of %lf is %lf\n",inputValue,cosineValue); getch(); return 0; }
When the above program is compiled and run, it will produce the following results.
Please enter the value to calculate cosine value :0.5 cosine value of 0.500000 is 0.877583
Similar Functions
Other C programming language functions that are similar to the cosine function
suggested for you
User defined function in C language
Arithmetic functions in C Language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…