===========================================================================
CODING
#include<all.h>
void main()
{
clrscr();
double q,sum=0,N=0,x=0;
int n,i;
cout<<"\nEnter number: ";
cin>>n;
cout<<"\nEnter Base: ";
cin>>x;
cout<<"\n";
for(i=1;i<=n;i++)
{
for(q=1,N=1;q<=i;q++)
{
N=q*N;
}
if(i%2!=0)
{
sum=-pow(x,i)/N+sum;
if(i<n)
cout<<" - ("<<x<<"^"<<i<<"/"<<i<<"!)";
else if(i==n)
cout<<" - ("<<x<<"^"<<i<<"/"<<i<<"!) = ";
}
else
{
sum=pow(x,i)/N+sum;
if(i<n)
cout<<" + ("<<x<<"^"<<i<<"/"<<i<<"!)";
else if(i==n)
cout<<" + ("<<x<<"^"<<i<<"/"<<i<<"!) = ";
}
}
cout<<sum;
getch();
}
CODING
#include<all.h>
void main()
{
clrscr();
double q,sum=0,N=0,x=0;
int n,i;
cout<<"\nEnter number: ";
cin>>n;
cout<<"\nEnter Base: ";
cin>>x;
cout<<"\n";
for(i=1;i<=n;i++)
{
for(q=1,N=1;q<=i;q++)
{
N=q*N;
}
if(i%2!=0)
{
sum=-pow(x,i)/N+sum;
if(i<n)
cout<<" - ("<<x<<"^"<<i<<"/"<<i<<"!)";
else if(i==n)
cout<<" - ("<<x<<"^"<<i<<"/"<<i<<"!) = ";
}
else
{
sum=pow(x,i)/N+sum;
if(i<n)
cout<<" + ("<<x<<"^"<<i<<"/"<<i<<"!)";
else if(i==n)
cout<<" + ("<<x<<"^"<<i<<"/"<<i<<"!) = ";
}
}
cout<<sum;
getch();
}
===========================================================================
No comments:
Post a Comment