Need help in LMC coding: Calculate the sum from 1 to a number inputted by users
For example, if user inputs 5, calculate 1+2+3+4+5 and output 15...
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Not the answer you are looking for? Search for more explanations.
You could start by choosing one symbol from the flowchart and code for it. Then do it again and again until you have all the symbols coded. Then you just have to "smooth out" the code between the symbols.
When in doubt, decompose (break down) the problem into smaller problems. Eventually a solution will appear.
@ParthKohli need help!!
its not compiling.. >.<
LOOP SUB ONE
QUIT LDA SUM
ONE DAT 1
thanks meepi, can u explains the branching part?
First we store the input in SUM
Then we substract 1 from the accumulator, and store the new number in TEMP
next we load SUM into the accumulator, and add TEMP and we store this in SUM again
then we load temp into the accumulator
BRZ check if temp is 0, in which case we're finished (5 + 4 + 3 + 2 + 1 + 0, we have the sum), and if it is we branch to QUIT
otherwise we use BRA to go back to the top of the loop and repeat the process
alright so u took temp as a variable to store the new #?
each iteration of the loop temp gets lowered by 1 and added to the sum in SUM
if temp is 0 we're done
temp is used as a countdown from input to 0, and each time the loop runs we add it to sum and substract 1 from it
got it now! thank you very much for your help! I appreciated!