peteryoungy
Badges: 12
Rep:
?
#1
Report Thread starter 1 month ago
#1
hey guys can someone please help me to answer this question for me. its very hard for me.
1. (a) How many lines of output will the following pseudocode algorithm produce?
Show your calculation. [3]
for a = 8 to 19 step 4
for b = 1 to 3
if a mod b >= b/3 then
if a/4 <= b+1 then
print (“Homer”)
else
print (“Marge”)
endif
else
print (“Bart”)
endif
next b
next a

(b) Trace through the pseudocode and write down what is output. [4]

thanks
0
reply
cvgk
Badges: 11
Rep:
?
#2
Report 1 month ago
#2
I show you beginning you continue
a=8 b=1 , 8 mod 1 =0 1/3 =0 0==0
a/4 = 2 b+1 =2 print Marge... it continues.. the solution is too long you need to understand logic and try it using a programming language
0
reply
peteryoungy
Badges: 12
Rep:
?
#3
Report Thread starter 1 month ago
#3
(Original post by cvgk)
I show you beginning you continue
a=8 b=1 , 8 mod 1 =0 1/3 =0 0==0
a/4 = 2 b+1 =2 print Marge... it continues.. the solution is too long you need to understand logic and try it using a programming language
thanks i will try and figure it out when i convert this into python.

btw do you know how you can get the answer for part b.
0
reply
cvgk
Badges: 11
Rep:
?
#4
Report 1 month ago
#4
(Original post by peteryoungy)
hey guys can someone please help me to answer this question for me. its very hard for me.
1. (a) How many lines of output will the following pseudocode algorithm produce?
Show your calculation. [3]
for a = 8 to 19 step 4
for b = 1 to 3
if a mod b >= b/3 then
if a/4 <= b+1 then
print (“Homer”)
else
print (“Marge”)
endif
else
print (“Bart”)
endif
next b
next a

(b) Trace through the pseudocode and write down what is output. [4]

thanks
homer
homer
homer
homer
homer
homer
Marge
homer
homer
Marge
Marge
homer
0
reply
cvgk
Badges: 11
Rep:
?
#5
Report 1 month ago
#5
(Original post by peteryoungy)
thanks i will try and figure it out when i convert this into python.

btw do you know how you can get the answer for part b.
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
Last edited by cvgk; 1 month ago
0
reply
cvgk
Badges: 11
Rep:
?
#6
Report 1 month ago
#6
(Original post by cvgk)
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
yo can do it using while loop as well.
0
reply
peteryoungy
Badges: 12
Rep:
?
#7
Report Thread starter 1 month ago
#7
(Original post by cvgk)
for(int a=8;a<=19)
{
for(int b=1;b<=3)
{
if((a%b)>=b/3)
{
if((a/4)<=b+1)
{
System.out.println("homer");
}else{
System.out.println("Marge");
}
}else{
System.out.println("bart");
}
b++;
a++;
}
}
my java code,check one more time may be something can be wrong
Thanks do you know how to do it in python language. I havn't learnt java. This will be very strange for my teacher.
0
reply
cvgk
Badges: 11
Rep:
?
#8
Report 1 month ago
#8
(Original post by peteryoungy)
Thanks do you know how to do it in python language. I havn't learnt java. This will be very strange for my teacher.
Sorry I don't know python if you don't mind are you going to university or high school , is this from algorithm lecture ?
0
reply
cvgk
Badges: 11
Rep:
?
#9
Report 1 month ago
#9
but don't be scared loops are similar just you need to change instead of System.out.println() use print in python.that is it.
0
reply
peteryoungy
Badges: 12
Rep:
?
#10
Report Thread starter 1 month ago
#10
i am 6 form and only know python.
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Has your education been disrupted this academic year due to the pandemic?

Yes (124)
87.32%
No (18)
12.68%

Watched Threads

View All