I have to change this code from Turing to C language but I'm not sure how.
Code:var a : array 1 .. 10 of intvar n, x, sum, offer : int var avg : real a (1) := 100 a (2) := 500 a (3) := 1000 a (4) := 5000 a (5) := 10000 a (6) := 25000 a (7) := 50000 a (8) := 100000 a (9) := 500000 a (10) := 1000000 get n for i : 1 .. n get x a (x) := 0 end for sum := 0 for i : 1 .. 10 sum := sum + a (i) end for avg := sum / (10 - n) get offer if offer > avg then put "deal" else put "no deal" end if
I can easily translate most of the program except for this part. I know its a loop, but how would you change this? :
Help please?Code:get n for i : 1 .. n get x a (x) := 0 end for sum := 0 for i : 1 .. 10 sum := sum + a (i) end for avg := sum / (10 - n)
EDIT: Alright I somewhat figured this. The first loop is to check how many inputs are left. There are 11 inputs available in total. For ex, if a user enter 2 in the beginning, there are 10 inputs left to be taken from the user. Is there a way to program this command using a loop?



LinkBack URL
About LinkBacks


