write Series of this program 1+-3+5+-7+9+-11 in c++
-
hey guys I am new for c++ and I wana to write program in C++, that will generate the Series of this program 1+-3+5+-7+9+-11..... who can help me
-
hey guys I am new for c++ and I wana to write program in C++, that will generate the Series of this program 1+-3+5+-7+9+-11..... who can help me
You can use a
for
loop that starts a counter from 1 and increments it by 2 each time. For each alternate path through the loop multiply the counter by -1. You can check for the alternate path by toggling abool
variable totrue
andfalse
.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
hey guys I am new for c++ and I wana to write program in C++, that will generate the Series of this program 1+-3+5+-7+9+-11..... who can help me
I can only point you in the right direction.
#include
using namespace std;int main()
{
int n=43, sum = 0,neg= 1;for(int i = 1; i <= n; i+=2) { sum += (i\*neg); cout <<"i="<
-
hey guys I am new for c++ and I wana to write program in C++, that will generate the Series of this program 1+-3+5+-7+9+-11..... who can help me
#include main() { int n; cout<<"Enter the Number:"; cin>>n; for(int i=1,j=1;j<=n;i+=2,j++) { if(i==1) cout<
-
#include main() { int n; cout<<"Enter the Number:"; cin>>n; for(int i=1,j=1;j<=n;i+=2,j++) { if(i==1) cout<