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
@Christos
@Cal.lavender u get it ???
I don't actually understand what the question is asking...
are we dividing n! by sum, or n by sum?
its \[input number \div Sum\]
@hari5719 I don't have the slightest idea about computer sciences, sorry
oh its ok
I still don't understand what's going on. you want \[\frac{\sum_{i=1}^{n}i}{n!}\]
is that correct?
ya i guess whats the sigma signify
you want, for n=5, (1*2*3*4*5)/(1+2+3+4+5)?
yea thats right
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
sum is suppose to be 1
it might be easier for you to actually implement this code in say, python
idk python so much i know vb ,html , learnin java
well what are the errors in the code @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?
it says this i have no clue ..@inkyvoyd
ok why are we getting an error? what kind of error is it? what happened?
division by zero error its because sum = 0 right ??
yes.
so what might we initialize sum to?
is it one ???
well, change it to 1 and then run the code... if for 1 to 5, what answer do we expect?
it says 1 ?
yes, and what should we expect for n=5?
says 1 check it
@paki @ParthKohli @pooja195
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.
And I feel like number 5 should be inversed meaning it should be sum divided by n
oh thx u get any more
@christos can u find the third error
what is your ans?
i got one as sum=0 , 5/sum , and i dont know the other @rvc
input no n then m<-n!
okay i get the same errors as u got
yeah so whaats the last one ?? @rvc
6 next is for what?
i think to go to the next number @rvc
@hari5719 that is correct
oh ok @kva1992 then what is the other error
not sure i finally got a computer so let me take a look at the problem properly.
oh thx
this is more of a question than an answer but wouldnt 1 be incorrect? Read what it says carefully.
"inputs a number, n," never in there does it state that n is the inputed number
i may be over analyzing but that's what i can see tbh
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
how is it 1 ??? i know 3 and 5 are right but how 1?? @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
Join our real-time social learning platform and learn together with your friends!