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