|
-
July 5th, 2010, 09:36 AM
#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
Answer=0
Am I right ?
Hello, I am a college junior
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|