Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-04-05 02:53:34

chetah
Member
Registered: 2008-02-15
Posts: 32

Discrete Math Pseudocode

Following the execution of this program segment, which value of n is printed?
N = 3
Sum = 0
While sum < 10,000 do
    Begin
        N = N + 7
        Sum = sum + n
    End
Print N

I am able to check my answer by typing in the code above.  My question is, how do I approach this question in an examination setting?  It would take forever to trace.

Offline

#2 2008-04-05 03:54:39

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: Discrete Math Pseudocode

come up with a recurrence relation for n and sum, then find the close form solution.


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#3 2008-04-05 21:25:19

chetah
Member
Registered: 2008-02-15
Posts: 32

Re: Discrete Math Pseudocode

Explain the concept of close form for me please.

Offline

#4 2008-04-05 21:40:49

Dragonshade
Member
Registered: 2008-01-16
Posts: 147

Re: Discrete Math Pseudocode

correct me if I am wrong

Last edited by Dragonshade (2008-04-05 21:45:34)

Offline

#5 2008-04-05 21:46:36

chetah
Member
Registered: 2008-02-15
Posts: 32

Re: Discrete Math Pseudocode

Not quite certain, when I typed it on my system, the result is something like 1118.

Offline

#6 2008-04-05 22:02:56

Dragonshade
Member
Registered: 2008-01-16
Posts: 147

Re: Discrete Math Pseudocode

But I test it with C++ , I got 374 as well

#include <iostream>

using namespace std;

int main()
{
  int n=3;
  int Sum=0;
do
{
    n=n+7;
    Sum = Sum+n;
}while (Sum < 10000);

cout << n;

return 0;
}

Offline

#7 2008-04-06 23:47:07

chetah
Member
Registered: 2008-02-15
Posts: 32

Re: Discrete Math Pseudocode

you are correct, I was testing a number greater than 3.

Offline

Board footer

Powered by FluxBB