Number Series 4

Description:

Write a Program to Print Series 1 -4 7 -10 . . . Test Case 1 Input (stdin) 5 Expected Output 1 -4 7 -10 13 Test Case 2 Input (stdin) 7 Expected Output 1 -4 7 -10 13 -16 19

Program :

#include <iostream>
using namespace std;
int main()
{
int n,i,a=1;
  cin>>n;
  cout<<"1 ";
  for(i=0;i<n-1;i++)
  {
    if(i%2==0)
  cout<<"-";
    a=a+3;
    cout<<a<<" ";
    }
 return 0;
}