Dry running this program

This is a program to find answer of sinx function. I've dry run this program but i'm quite confused.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  #include<iostream>
using namespace std;

int main()
{
	int i,j,n,fact,sign=-1;
	float x=0, p=0,sum=0;
	cout<<"Enter the value of x : ";
	cin>>x;
	cout<<"Enter the number of terms : ";
	cin>>n;
	for(i=1;i<=n;i=i+2)
	{ 
		p=1;
        fact=1;
		for(j=1;j<=i;j++)
		{
			p=p*x;
			fact=fact*j;
		}
		sign=-1*sign;
		sum=sum+(sign*p/fact);
	}
	cout<<"sin "<<endl;
	cout<<sum;

	system("pause");
	return 0;
}
I might be wrong but it looks like the code computes the Taylor expansion coefficient for sin(x), isn't it?
Registered users can post here. Sign in or register to post.