Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Example Program Functions
  6. Computation of sine series

Computation of sine series

According to sine series:

Where x in radians

#include<stdio.h>
#include<math.h>
float cal_Sin(float r, int a);
double factorial(int n)
{
	if(n == 0)
	{
		return 1;
	}
	else
	{
		return n*factorial(n-1);
	}
}
int main()
{
	int x, n;
	float radian, res;
	printf("Enter the value of x in degrees \n");
	scanf("%d", &x);
	printf("Enter the power of end term:");
	scanf("%d",&n);
	// convert x to radians
	radian = x * (3.14 / 180);
	res = cal_Sin(radian, n);
	printf("The value of sin(%d) is %f",x,res);
	return 0;
}
float cal_Sin(float rad, int n)
{
	float sum = rad;
	int i=3, sign = -1;
	while(i<=n)
	{
		sum = sum + sign *(pow(rad, i) / factorial (i));
		sign = sign * -1;
		i= i +2;
	}
	return sum;
}

Output

Enter the value of x in degrees
60
Enter the power of end term:10
The value of sin(60) is 0.865760

Views: 2

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments