Write a program in c++ to find the sum of following series : s = 1- 2+3-4+........... Upto nth team
#include<iostream>
using namespace std;
void main (){
int s= 0 ,i, n ;
cout<<"Enter Last Term : ";
cin>>n;
for(i=1; i<=n; i++)
{
if (i%2==1)
s=s+1;
else
s=s-1;
}
cout<<"sum="<<s;
}
Post a Comment