#include<iostream.h>
#include<conio.h>
class summation
{
int sum;
public:
void s();
};
void summation::s()
{
sum=0;
int n;
cout<<"enter the number of terms whose sum you want in the
series"<<endl;
cin>>n;
for(int
i=1;i<=n;i++)
{
if(i%2!=0)
sum=sum+i;
else
sum=sum-i;
}
cout<<"the sum is :"<<sum;
}
void main()
{
clrscr();
summation obj;
obj.s();
getch();
}
Comments
Post a Comment