Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (hari5719):

The following section of pseudocode inputs a number, n, multiplies together 1 x 2 x 3 x………. x n , calculates input number /sum and outputs result of the calculation. Locate the 3 errors and suggest a corrected piece of code. 1 input n 2 for mult = 1 to n 3 sum =0 4 sum = sum * mult 5 result = n / sum 6 next 7 print result

OpenStudy (hari5719):

@Christos

OpenStudy (hari5719):

@Cal.lavender u get it ???

OpenStudy (inkyvoyd):

I don't actually understand what the question is asking...

OpenStudy (inkyvoyd):

are we dividing n! by sum, or n by sum?

OpenStudy (hari5719):

its \[input number \div Sum\]

OpenStudy (cal.lavender):

@hari5719 I don't have the slightest idea about computer sciences, sorry

OpenStudy (hari5719):

oh its ok

OpenStudy (inkyvoyd):

I still don't understand what's going on. you want \[\frac{\sum_{i=1}^{n}i}{n!}\]

OpenStudy (inkyvoyd):

is that correct?

OpenStudy (hari5719):

ya i guess whats the sigma signify

OpenStudy (inkyvoyd):

you want, for n=5, (1*2*3*4*5)/(1+2+3+4+5)?

OpenStudy (hari5719):

yea thats right

OpenStudy (inkyvoyd):

1 input n 2 for mult = 1 to n 3 sum =0 4 sum = sum * mult 5 result = n / sum 6 next 7 print result Try running this code in your head for n=3... what happens? just go through the first 5 steps

OpenStudy (hari5719):

sum is suppose to be 1

OpenStudy (inkyvoyd):

it might be easier for you to actually implement this code in say, python

OpenStudy (hari5719):

idk python so much i know vb ,html , learnin java

OpenStudy (hari5719):

well what are the errors in the code @inkyvoyd

OpenStudy (inkyvoyd):

go here http://pythonfiddle.com/ copy and paste this code which I have translated to python n=5 for mult in range(1,n): sum = 0 sum = sum * mult result = n / sum print(result) click run what happens?

OpenStudy (hari5719):

it says this i have no clue ..@inkyvoyd

OpenStudy (inkyvoyd):

ok why are we getting an error? what kind of error is it? what happened?

OpenStudy (hari5719):

division by zero error its because sum = 0 right ??

OpenStudy (inkyvoyd):

yes.

OpenStudy (inkyvoyd):

so what might we initialize sum to?

OpenStudy (hari5719):

is it one ???

OpenStudy (inkyvoyd):

well, change it to 1 and then run the code... if for 1 to 5, what answer do we expect?

OpenStudy (hari5719):

it says 1 ?

OpenStudy (inkyvoyd):

yes, and what should we expect for n=5?

OpenStudy (hari5719):

says 1 check it

OpenStudy (hari5719):

@paki @ParthKohli @pooja195

OpenStudy (kva1992):

It looks like they are taking the average. Well right off the back I cN tell 3 is wrong. Let me explain why. If we state sum is = 0 and then in step 4 you multiply sum by n no matter what the number is sum will always equal zero.

OpenStudy (kva1992):

And I feel like number 5 should be inversed meaning it should be sum divided by n

OpenStudy (hari5719):

oh thx u get any more

OpenStudy (hari5719):

@christos can u find the third error

rvc (rvc):

what is your ans?

OpenStudy (hari5719):

i got one as sum=0 , 5/sum , and i dont know the other @rvc

rvc (rvc):

input no n then m<-n!

rvc (rvc):

okay i get the same errors as u got

OpenStudy (hari5719):

yeah so whaats the last one ?? @rvc

rvc (rvc):

6 next is for what?

OpenStudy (hari5719):

i think to go to the next number @rvc

OpenStudy (kva1992):

@hari5719 that is correct

OpenStudy (hari5719):

oh ok @kva1992 then what is the other error

OpenStudy (kva1992):

not sure i finally got a computer so let me take a look at the problem properly.

OpenStudy (hari5719):

oh thx

OpenStudy (kva1992):

this is more of a question than an answer but wouldnt 1 be incorrect? Read what it says carefully.

OpenStudy (kva1992):

"inputs a number, n," never in there does it state that n is the inputed number

OpenStudy (kva1992):

i may be over analyzing but that's what i can see tbh

OpenStudy (kva1992):

If i had to guess from the knowledge i have i would say its 1 3 and 5 but dont quote me i could be wrong

OpenStudy (hari5719):

how is it 1 ??? i know 3 and 5 are right but how 1?? @kva1992

OpenStudy (kva1992):

Because no where in the problem does it state input is n it says you have an input, n that doesn't mean input equals n does that make sense? I could say n is 20 and input is what the user typed in other words I would comprehend it as n and input are two different variables

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!