Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. write Series of this program 1+-3+5+-7+9+-11 in c++

write Series of this program 1+-3+5+-7+9+-11 in c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Beiniam
    wrote on last edited by
    #1

    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

    J _ S C 4 Replies Last reply
    0
    • B Beiniam

      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

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      What have you tried so far?

      1 Reply Last reply
      0
      • B Beiniam

        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

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        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 a bool variable to true and false.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        1 Reply Last reply
        0
        • B Beiniam

          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

          S Offline
          S Offline
          Software_Developer
          wrote on last edited by
          #4

          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="<
          
          1 Reply Last reply
          0
          • B Beiniam

            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

            C Offline
            C Offline
            C_Vivek Arya
            wrote on last edited by
            #5

            #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<

            C 1 Reply Last reply
            0
            • C C_Vivek Arya

              #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<

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              I see your C++ compiler is a bit dated.

              Veni, vidi, vici.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups