Problem : Calculate value of sin(x)
// I have made some changes in input output statements so that you dont copy this question in OJ but you can derieve motivation from it.
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
unsigned long long int fact(int a)
{
unsigned long long int f=1;
for(int i=1;i<=a;i++)
{
f=f*i;
}
cout<<"the fact "<<f<<"\n";
return f;
}
int main()
{
double x;
cin>>x;
double radian=3.14159265358979323846264*x/180;
int t=1;
double sum=0.0;
for(int i=1;i<=58;i+=2) //58 is the limit
{
sum=sum+((t)*pow(radian,i)/fact(i));
cout<<sum<<"\n";
t*=-1;
}
cout<<"the final sum "<<sum;
}
No comments:
Post a Comment