Attention Computer Science Graduates - Education - Nairaland
Nairaland Forum › Nairaland General › Education › Attention Computer Science Graduates (514 Views)
| Attention Computer Science Graduates by walletxtra(op): 6:25pm On Jun 28, 2017 |
Kindly help me solve this BASIC programming questions: 10 LET K = 2 20 LET L = 9 30 LET SUM =0 40 FOR J = K TO STEP 2 50 SUM = SUM+ J^2 60 PRINT "ANSWER=", SUM 70 NEXT J 80 END A. How many times will the statement lines 50 and 60 be repeated? B. What is the best sequence of output for the program? C. What is the last output to be displayed by the program? |
| Re: Attention Computer Science Graduates by AlanTuringAI: 6:49pm On Jun 28, 2017 |
walletxtra:Solutions : A. I want to believe you omitted L after the TO in line 40,right? If so, statement lines 50 and 60 will be repeated four (4) times as the loop will only iterate 4 times since the loop counting variable J will have four values: 2,4,6 and 8 B. Best sequence of output for the program is by swapping the contents of statement lines 60 and 70. That way we only have one final value of SUM to be displayed as the output of the program, instead of four values as the program currently is. C. Last output of the program is: ANSWER= 120. This is obtained this way: For values of J= 2,4,6,8 in each iteration, SUM =0 + 2^2 = 4 ----->1st iteration SUM =4 + 4^2 = 20 ----->2nd iteration SUM =20 + 6^2 = 56----->3rd iteration Lastly, SUM =56 + 8^2 = 120 ----->4th iteration Best of luck. |
| Re: Attention Computer Science Graduates by walletxtra(op): 9:46pm On Jun 28, 2017 |
Thanks a bunch |
| Re: Attention Computer Science Graduates by AlanTuringAI: 10:49pm On Jun 28, 2017 |
walletxtra:You're welcome. |
Faculty of Life Science Graduates Of AAU dress like Marlians • Chemical Engineering Vs Computer Science Which Has More Calculations??? • What Are The Career Opportunities For A Political Science Graduates? • 2 • 3 • 4
The Power Of The Tongue Is Overrated • Organizing Your Research Paper: The Introduction • Unilorin Aspirants Session