Click here to Skip to main content
15,867,310 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In the code fragment below, start & end are integer values and square (x) is a function that returns true if x is a perfect square and false otherwise.
i:=0
j:=0
k:=0
for m in [start, start+1,......, end] {
if (square (m)=true) {
i:=i+m*m;
k:=k+m*m;
}else{
j:=j+m*2;
k:=k+m*2;
}
}

Which of the following are correct statements about the relationship between i,jand k?
a) k= i*i+j*2 if (end-start ) is even 
b) k= i*i+j if (end-start) is odd
c) j= k-i if (end - start) is even 
d) i= k-j if (end-start) is odd


What I have tried:

Yes , but cannot understand the question
Posted
Updated 6-Jan-23 22:08pm
v2
Comments
Richard MacCutchan 7-Jan-23 5:06am    
If you cannot understand the question then you need to talk to your teacher.
Dave Kreskowiak 7-Jan-23 10:53am    
Have a virtual 5.
Richard MacCutchan 7-Jan-23 11:09am    
Thanks. My six-year old grandson could do better than some of these guys.

If you are able to understand the pseudocode then, try executing it manually (with pencil and paper) for very small input ranges (e.g. start=1, end=4). Once you have computed the result, you may easily discard the incompatible statements.

You may also try to actually implement the code in you favourite programming language and experimentally see what happens.

On the other hand, if you aren't currently able to grasp the pseudocode, then post here your doubts about, we may help you proceeding.
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Were you planning on posting every homework assignment you are given here? How to solve the following pseudo code?[^]

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900