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. (20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

(20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

Scheduled Pinned Locked Moved C / C++ / MFC
question
31 Posts 8 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.
  • N Offline
    N Offline
    Nusrat Islam Papiya
    wrote on last edited by
    #1

    (20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

    J L J A 4 Replies Last reply
    0
    • N Nusrat Islam Papiya

      (20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

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

      What have you tried? Can you write the code for evaluating a single term?

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      1 Reply Last reply
      0
      • N Nusrat Islam Papiya

        (20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can see the sequence, which uses m*(m+3) not minus: 1. Set m = 20 2. Multiply m by (m + 3) 3. Add the result to the running total 4. Add 5 to m 5. Goto 2.

        L 1 Reply Last reply
        0
        • L Lost User

          You can see the sequence, which uses m*(m+3) not minus: 1. Set m = 20 2. Multiply m by (m + 3) 3. Add the result to the running total 4. Add 5 to m 5. Goto 2.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          M=23 uses (m*(m-3)) or ((m-3)*m)

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          L 1 Reply Last reply
          0
          • L Lost User

            M=23 uses (m*(m-3)) or ((m-3)*m)

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            If m is the first operand, as in (20 * 23) then the formula is m*(m+3). Why would you read it the other way round, or am I missing something mathematical?

            L 1 Reply Last reply
            0
            • L Lost User

              If m is the first operand, as in (20 * 23) then the formula is m*(m+3). Why would you read it the other way round, or am I missing something mathematical?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You substituted (M*(M+3)) for (M*(m-3)). I'm simply reading what the OP "posted". I'm the one that's missing something regarding you changing it.

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

              L J 2 Replies Last reply
              0
              • L Lost User

                You substituted (M*(M+3)) for (M*(m-3)). I'm simply reading what the OP "posted". I'm the one that's missing something regarding you changing it.

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I did not substitute, I corrected. It's pretty obvious that the questioner made a mistake and typed the wrong sign.

                A 1 Reply Last reply
                0
                • N Nusrat Islam Papiya

                  (20*23) + (25*28) + (30*33) + (35*38) +...........+ (m*(m-3)) what is the c programmimg code of the summetion of this series

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  Looks like homework for recursion. So look up recursion examples and then modify those.

                  L T 2 Replies Last reply
                  0
                  • L Lost User

                    You substituted (M*(M+3)) for (M*(m-3)). I'm simply reading what the OP "posted". I'm the one that's missing something regarding you changing it.

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    My presumption would be that OP did not transcribe it correctly. The sequence as suggested by the dots, rather than the explicit terms, is not defined as it is posted. But is defined with the suggested correction.

                    1 Reply Last reply
                    0
                    • J jschell

                      Looks like homework for recursion. So look up recursion examples and then modify those.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      And then we'll see the post which says, "my program fails with stack overflow" ...

                      J 1 Reply Last reply
                      0
                      • J jschell

                        Looks like homework for recursion. So look up recursion examples and then modify those.

                        T Offline
                        T Offline
                        trønderen
                        wrote on last edited by
                        #11

                        Anyone who seriously considers this problem for a recursive solution must be one who has just recently learned about recursion and thinks of it as a universal cure for all the ills of the programming world. (Any 'for' loop can easily be rewritten to a recursive solution!)

                        R J 2 Replies Last reply
                        0
                        • T trønderen

                          Anyone who seriously considers this problem for a recursive solution must be one who has just recently learned about recursion and thinks of it as a universal cure for all the ills of the programming world. (Any 'for' loop can easily be rewritten to a recursive solution!)

                          R Offline
                          R Offline
                          Richard Deeming
                          wrote on last edited by
                          #12

                          You wouldn't use a recursive solution in real code. But if it's a homework assignment to teach the student about recursion, as jschell suggested... :)


                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          K 1 Reply Last reply
                          0
                          • L Lost User

                            And then we'll see the post which says, "my program fails with stack overflow" ...

                            J Offline
                            J Offline
                            jschell
                            wrote on last edited by
                            #13

                            Well presumably the teacher will provide inputs that do not lead to that.

                            L 1 Reply Last reply
                            0
                            • J jschell

                              Well presumably the teacher will provide inputs that do not lead to that.

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              Never presume. ;)

                              J 1 Reply Last reply
                              0
                              • T trønderen

                                Anyone who seriously considers this problem for a recursive solution must be one who has just recently learned about recursion and thinks of it as a universal cure for all the ills of the programming world. (Any 'for' loop can easily be rewritten to a recursive solution!)

                                J Offline
                                J Offline
                                jschell
                                wrote on last edited by
                                #15

                                quote class="quote">

                                trønderen wrote:

                                Anyone who seriously considers this problem for a recursive solution As I said "Looks like homework for recursion.." But with my 40 years of development experience and numerous cases of recursion unrolling not to mention more than 30 years of formal designs and 20 of architecture... Myself I would probably start by looking at the requirements to see why either solution was needed. Certainly in the past I have, after using all that experience, decided that a simple look up in a static data block would completely meet the needs of the application/requirements. And of course that solution would be much more efficient than recursion or the similar unrolled version. In case you were unaware of that.

                                T L 2 Replies Last reply
                                0
                                • L Lost User

                                  Never presume. ;)

                                  J Offline
                                  J Offline
                                  jschell
                                  wrote on last edited by
                                  #16

                                  I would however presume that if the teacher is teaching recursion and then assigns the above problem then the teacher is going to expect a code that does recursion. Whether it causes a stack overflow is outside the bounds of what the teacher is teaching. Although perhaps a teacher that is clever (or trying to be clever) might even provide inputs that would cause an overflow just so the students would need to fumble about with that.

                                  L 1 Reply Last reply
                                  0
                                  • J jschell

                                    quote class="quote">

                                    trønderen wrote:

                                    Anyone who seriously considers this problem for a recursive solution As I said "Looks like homework for recursion.." But with my 40 years of development experience and numerous cases of recursion unrolling not to mention more than 30 years of formal designs and 20 of architecture... Myself I would probably start by looking at the requirements to see why either solution was needed. Certainly in the past I have, after using all that experience, decided that a simple look up in a static data block would completely meet the needs of the application/requirements. And of course that solution would be much more efficient than recursion or the similar unrolled version. In case you were unaware of that.

                                    T Offline
                                    T Offline
                                    trønderen
                                    wrote on last edited by
                                    #17

                                    If you teach recursion to students, you should illustrate it, and create homework assignments, with problems suited for recursion. Students should not, through inappropriate homework assignments, learn to use the wrong tools for the problem at hand. So if that is the case here, the teacher should be blamed. Especially if the assignment is as suggested in the subject line, with no hint of recursion in the problem statement. A lot of problems can be described in a very concise form in recursive terms, but can easily be implemented as an iteration (and most students will not discover that and make a recursive implementation ... I speak of experience). Here is no trace of a recursive problem description.

                                    J 1 Reply Last reply
                                    0
                                    • R Richard Deeming

                                      You wouldn't use a recursive solution in real code. But if it's a homework assignment to teach the student about recursion, as jschell suggested... :)


                                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                      K Offline
                                      K Offline
                                      kalberts
                                      wrote on last edited by
                                      #18

                                      Richard Deeming wrote:

                                      But if it's a homework assignment to teach the student about recursion, as jschell suggested...

                                      ... it is a very poor choice. :-) When teaching, I did give my students a recursive problem statement to solve. Most of the solutions were recursive. The main point of this exercise was to, in the next round, show how some recursions could be rolled out to loops; the problem statement was selected for this specific purpose: Learning when not to use recursion, even when it looks like the straightforward, obvious solution. I never wold give my students a 'linear' problem statement (such as the one in the subject line), hoping that they would discover 'Hey, this iteration can be reformualated as a recursive method! Let's do that!' If I were a teacher of higher math, I might use something in that direction to teach them to identify recursive structures. But I was a programming teacher. That is very different.

                                      J 1 Reply Last reply
                                      0
                                      • J jschell

                                        I would however presume that if the teacher is teaching recursion and then assigns the above problem then the teacher is going to expect a code that does recursion. Whether it causes a stack overflow is outside the bounds of what the teacher is teaching. Although perhaps a teacher that is clever (or trying to be clever) might even provide inputs that would cause an overflow just so the students would need to fumble about with that.

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        If what you say is true, then the student would most likely have been able to figure the answer for him/her self.

                                        J 1 Reply Last reply
                                        0
                                        • J jschell

                                          quote class="quote">

                                          trønderen wrote:

                                          Anyone who seriously considers this problem for a recursive solution As I said "Looks like homework for recursion.." But with my 40 years of development experience and numerous cases of recursion unrolling not to mention more than 30 years of formal designs and 20 of architecture... Myself I would probably start by looking at the requirements to see why either solution was needed. Certainly in the past I have, after using all that experience, decided that a simple look up in a static data block would completely meet the needs of the application/requirements. And of course that solution would be much more efficient than recursion or the similar unrolled version. In case you were unaware of that.

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #20

                                          jschell wrote:

                                          with my 40 years of development experience and numerous cases of recursion unrolling not to mention more than 30 years of formal designs and 20 of architecture

                                          Holy mackerel, that's 90 years dude. :omg:

                                          J A 2 Replies 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