Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

COS Function in C

by suresh

The C cos Function is a C Math Library Function, used to calculate the Trigonometry Cosine value for the specified expression. The syntax of the cos in C Programming is

double cos(double number);

The COS function in C will return the value between -1 and 1. Before we get into to the syntax, let us see the mathematical formula behind this C Trigonometry Cosine function:

cos(x) = Length of the Adjacent Side / Length of the Hypotenuse

COS Function in C Example

The cos function in the math library allows you to find the trigonometry Cosine for the specified values.

This C program, ask the user to enter his/her own value, and then it will find the cosine value of the user-specified one

TIP : Please refer C ACOS Function article in C Programming to calculate the Arc Cosine of the specified expression.

/* Example for COS Function in C Programming */

#include <stdio.h>
#include <math.h>

int main()
{
  double cosValue, number;
  printf(" Please Enter the Value to calculate Cosine :  ");
  scanf("%lf", &number);
  
  cosValue = cos(number);
  
  printf("\n Cosine value of %lf = %f ", number, cosValue);
  
  return 0;
}

OUTPUT

COS Function in C Programming 1

C COSINE Function Example 2

In this C cosine function example, we are allowing the user to enter the value in degrees. Then we are converting the degrees to Radians. And finally, we are finding the cosine value of the radian.

/* Example for COS Function in C Programming */

#include <stdio.h>
#include <math.h>

#define PI 3.14
int main()
{
  double cosValue, radianVal, degreeVal;
  printf(" Please Enter an Angle in degrees :  ");
  scanf("%lf", &degreeVal);
  
  // Convert Dgree Value to Radian 
  radianVal = degreeVal * (PI/180);
  cosValue = cos(radianVal);
  
  printf("\n Cosine value of %f = %f ", degreeVal, cosValue);
  
  return 0;
}

OUTPUT

COS Function in C Programming 2

Placed Under: C Programming

  • C Comments
  • C Escape Sequence
  • C Programming Operators
  • C Arithmetic Operators
  • C Assignment Operators
  • C Bitwise Operators
  • C Conditional Operator
  • C Increment & Decrement Optr
  • C Logical Operators
  • C Relational Operators
  • C Sizeof Operator
  • C If Statement
  • C IF ELSE Statement
  • C Else If Statement
  • C Nested If
  • C Break Statement
  • C Continue Statement
  • C Goto Statement
  • C Switch Case
  • C For Loop
  • C While Loop
  • C Do While Loop
  • C Arrays
  • C Two Dimensional Array
  • C Multi Dimensional Array
  • C String
  • C Structures
  • C Nested Structures
  • C Array of Structures
  • C Structures and Functions
  • C Union
  • C Structure & Union differences
  • C Pointers
  • C Pass Pointers to Functions
  • C GETS
  • C fgets Function
  • C fgetc
  • C fputs function
  • C fputc
  • C Functions
  • C Types of Functions
  • C Pass Array to Functions
  • Call By Value & Call By Reference
  • C Recursion
  • C Program Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy