Please I want a solution to this question؟
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Jun 2010
Posts
5

## Please I want a solution to this question؟

public int Evaluate(s,t){
for loop {
if(s==0 || t==0)
return 0;
}
else if{
y=Evaluate(s,t-1);
return s+y;
}
}

By using stack to find
z=Evaluate(2,2)=???????????????????
Dont use Recourion

2. Junior Member
Join Date
Jun 2010
Posts
5

## Re: Please I want a solution to this question؟

Note :
But some of my answer was 4

3. Junior Member
Join Date
Jun 2010
Posts
5

## Re: Please I want a solution to this question؟

http://store2.up-00.com/Jun10/bPo33786.jpg
this quistion comming for me in the finale exam for Data Structuers

4. Elite Member
Join Date
May 2009
Posts
2,413

## Re: Please I want a solution to this question؟

I'm not quite sure what you're asking.

Is Evaluate given in some real language or is it pseudocode? What does,

for loop {

mean?

5. Junior Member
Join Date
Jun 2010
Posts
5

## Re: Please I want a solution to this question؟

oh yes
i dont main for loop
I do not remember the text of a good question

****************************************
public int Evaluate(s,t){
for {
if(s==0 || t==0)
return 0;
}
else if{
y=Evaluate(s,t-1);
return s+y;
}
}

****************************************

By using stack to find
z=Evaluate(2,2)=???????????????????
Dont use Recourion

The solution described in the link http://www.4shared.com/photo/0Nu72OYi/9999999999.html

Is the correct solution, as told by Dr.

Thus, the question was almost

6. ## Re: Please I want a solution to this question؟

How do you solve it using recurion ?

7. ## Re: Please I want a solution to this question؟

Hello, strange, so strange, I am still think it is 0 not 4

1.public int Evaluate(s,t){
2.{
3.if(s==0 || t==0)
4.return 0;
5.}
6.else if{
7.y=Evaluate(s,t-1); // this
8.return s+y;
9.}
10.}

Line 7 rerun line 1, so no value is put for y
t=2-1=1
s=2
line 3 checks t and s
unsatisfactorily, line 6 come again, line 7 again rerun line 1, still no value for y
t=1-1=0
s=2
Now t=0
line 2-3 checks t=0 so satisfied it returns 0

So the final result is 0, line 8 never reaches

Am I right ?

8. Elite Member
Join Date
May 2009
Posts
2,413

## Re: Please I want a solution to this question؟

Originally Posted by Lazyboy
Am I right ?
Does it stay put now, the 1 to 10 lines? Is this the version of the Evaluate function you're asking about?

And who is salemqeshta in relation to lazyboy?

Sorry for letting out some steam here but why is it so god dammed hard to state a problem in a precise and understandable way?
Last edited by nuzzle; July 5th, 2010 at 08:45 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•