sin() and cos() functions of math.h in C

In this article, we are going to know about the trigonometric functions sin() and cos() of math.h header file in C language and learn the process to use them.
Submitted by Manu Jemini, on March 17, 2018

If you are building a mathematical program then these two functions will solve many problems, as these two functions calculate the very popular trigonometric values of SIN and COS.

Now, these two things can be a little tricky, if the number is complicated, hence we should use math.h file after including in our program. These functions are easy to use and very compatible to help you build complex program easily.

To use sin() function all you need to do is pass a number as a parameter and this function will return a value of SIN for that number, which you can easily store in a variable. To use cos() function all you need to do is pass a number as a parameter and this function will return a value of COS for that number, which you can easily store in a variable.

math.h - sin() function Example in C

#include <stdio.h>
//to use 'sin()' function
#include <math.h>

int main()
{
	// set the type of variable
	float a, num;

	// message for user
	printf("Please enter a number from keyboard to find it's sin value\n");
	scanf("%f", &num);

	// storing the sin value
	a = sin(num);

	// printing the calculated value
	printf("value in sin is = %.4f\n", a);

	return 0;
}

Output

math.h cos() in c language

math.h - cos() function Example in C

#include <stdio.h>
//to use 'cos()' function
#include <math.h>

int main()
{
	// set the type of variable
	float a, number;

	// message for user
	printf("Please enter a number from keyboard to find it's cos value\n");
	scanf("%f", &number);

	// storing the cos value
	a = cos(number);

	// printing the calculated value
	printf("value in cos is = %.3f\n", a);

	return 0;
}

Output

math.h cos() in c language



Comments and Discussions!

Load comments ↻





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