Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,186,546 members, 7,929,771 topics. Date: Friday, 23 August 2024 at 10:18 PM

Attention Computer Science Graduates - Education - Nairaland

Nairaland Forum / Nairaland / General / Education / Attention Computer Science Graduates (454 Views)

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)

(1) (Reply) (Go Down)

Attention Computer Science Graduates by walletxtra: 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:
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?
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.

1 Like

Re: Attention Computer Science Graduates by walletxtra: 9:46pm On Jun 28, 2017
Thanks a bunch
Re: Attention Computer Science Graduates by AlanTuringAI: 10:49pm On Jun 28, 2017
walletxtra:
Thanks a bunch
You're welcome.

(1) (Reply)

2 Futarians Drown In A River / Organizing Your Research Paper: The Introduction / First Female Fields Medalist, ā€ˇMaryam Mirzakhani Dies At 40!.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.