Signup/Sign In
LAST UPDATED: MARCH 22, 2022

C++ Program To Print Given Series 1 -4 7 -10 . . . . . . . . . . . -40

Here, in this tutorial, we will see how to write the program for the given pattern and print the resultant series formed for the input number of terms by the user.

We can have multiple different approaches to writing the program, but the programs will be graded based on the time complexity.

C++ Program To Print The Series 1 -4 7 -10 . . . . . . . . . . . -40

#include<iostream>
 
using namespace std;
 
int main()
{
int i,a=-1,b;
for(i=1;i<=40;i+=3)
{
a*=-1;
b=i;
b*=a;
cout<<b<<" ";
}
return 0;
}


1 -4 7 -10 13 -16 19 -22 25 -28 31 -34 37 -40

Conclusion

Here, in this tutorial mainly, we have to focus on the pattern of the series for how it is changing concerning the number of terms.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.