Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
110 views
in C Programming by (178k points)
Explain cos() Math Function in C

Please log in or register to answer this question.

1 Answer

0 votes
by (178k points)

Certainly! In C, the cos() function is part of the math library and is used to calculate the cosine of an angle. The function takes an angle in radians as input and returns the cosine of that angle as a floating-point value.

Here's an example code that demonstrates the usage of the cos() function in C:

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

int main() {
    double angle = 1.2;  // Angle in radians
    double result = cos(angle);

    printf("Cosine of %.2f radians is %.4f\n", angle, result);

    return 0;
}
 

In this example, we include the necessary header files <stdio.h> and <math.h>. The math.h header file provides the declaration of the cos() function.

Inside the main() function, we declare a variable angle and assign it a value of 1.2 radians. You can change this value to any angle in radians that you want to calculate the cosine for.

Next, we call the cos() function and pass the angle as its argument. The result is stored in the variable result.

Finally, we use printf() to display the original angle and the computed cosine value. The format specifier %.2f specifies that we want to display the angle with 2 decimal places, and %.4f specifies that we want to display the cosine value with 4 decimal places.

When you run this code, it will calculate the cosine of the angle 1.2 radians and print the result to the console.

Note: The cos() function expects the angle to be in radians. If you have an angle in degrees, you can convert it to radians using the formula: angle_in_radians = angle_in_degrees * (PI / 180), where PI is a constant representing the value of pi (approximately 3.14159).

Related questions

0 votes
1 answer
0 votes
1 answer
asked May 25, 2023 in C Programming by kvdevika (178k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked May 25, 2023 in C Programming by kvdevika (178k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...