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