function in C

cos function in C programming language

cos function in C programming language

In this tutorial, we will discuss cos function in C programming language

cos function in C programming language

Description

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 .

Declaration

The declaration of the cos()  in C programming language is

double cos(double x);

Parameters or Arguments

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.

Returns

The cos function returns cosine value  of x, measured in radians

Required header

The required header of the cos()  is

#include <math.h>

cos function in C programming language

Example

following example shows the usage of the cosine function.

Calculate cosine value – using variable

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

 

Calculate cosine value – Entered by user

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      

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

sqrt function in C language

pow function in C language

exp function in C language

log function in C language

log10 function in C language

trunc function in C language

 

 

suggested for you

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

                                                                  

 

 

Sine function in C programming Language
tan function in C programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago