You are not logged in.
Pages: 1
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
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
Explain the concept of close form for me please.
Offline
correct me if I am wrong
Last edited by Dragonshade (2008-04-05 21:45:34)
Offline
Not quite certain, when I typed it on my system, the result is something like 1118.
Offline
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
you are correct, I was testing a number greater than 3.
Offline
Pages: 1