***************************************************************************************************************************************************
A ‘C++’ Program to compute the Sine Series
***************************************************************************************************************************************************
Source code:
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 | #include<iostream.h> #include<conio.h> #include<math.h> void main() { int fact,n; float sum=0.0,x; clrscr(); cout<<"Enter x,n values :"; cin>>x>>n; for(int i=0,p=0;i<n;i++,p+=2) { fact=1; for(int j=p;j>=1;j--) fact=fact*j; sum=sum+(pow(-1,i)*pow(x,p)/fact); } cout<<"The sum of the sine series is :"<<sum; getch(); } /* OUTPUT ====== Enter x,n values :2 2 The sum of the sine series is :-1.00000 */ |
18 total views, 1 views today