ADVERTISEMENT
ADVERTISEMENT

Home » C programs » math.h header file functions

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.