Mathematical Functions in c programming langauage

C Programming Language / Function in C Language

1118

This program demonstrates the usage of various mathematical functions provided in the "math.h" header file of C. It initializes a variable "a" with the value 0.25 and then uses various functions such as abs(), acos(), asin(), atan(), atan2(), cos(), sin(), tan(), and sqrt() to perform mathematical operations on "a" and store the result in variable "b". Finally, it prints the value of "b" using the printf() function.

Program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
   	float a;
	float b;
	float pi = 3.14;
	a = 0.25;
	printf("value a = %.2f \n",a);
	b = abs(-a);
	printf("abs(a)=%.2f \n",b);
	b = acos(a);
	printf("acos(a)=%.2f \n",b);
	b = asin(a);
	printf("asin(a)=%.2f \n",b);
	b = atan(a);
	printf("abs(a)=%.2f \n",b);
	b = atan2(a,5);
	printf("atan(a,5)=%.2f \n",b);
	b = cos(a);
	printf("cos(a)=%.2f \n",b);
	b = sin(a);
	printf("sin(a)=%.2f \n",b);
	b = tan(a);
	printf("tan(a)=%.2f \n",b);
	b = sqrt(a);
	printf("sqrt(a)=%.2f \n",b);
	return 0;
}

Output:

value a = 0.25
abs(a)=0.00
acos(a)=1.32
asin(a)=0.25
abs(a)=0.24
atan(a,5)=0.05
cos(a)=0.97
sin(a)=0.25
tan(a)=0.26
sqrt(a)=0.50
Press any key to continue . . .

Explanation:


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.