Basic Program To Print Sum of First N Odd and Even Numbers

REM SUM OF FIRST N ODD AND EVEN NUMBERS USING GOSUB AND RETURN
CLS
10 INPUT “ENTER ANY VALUE(N)”; N
20 GOSUB 100
30 GOSUB 200
40 PRINT “SUM OF ODD NUM”; SUM1
50 PRINT “SUM OF EVEN NUM”; SUM2
60 END
100 SUM1 = 0
110 FOR I = 1 TO N
120 X = 2 * I – 1
130 SUM1 = SUM1 + X
140 NEXT I
150 RETURN
200 SUM2 = 0
210 FOR I = 1 TO N
220 X = 2 * I
230 SUM2 = SUM2 + X
240 NEXT I
250 RETURN

Please follow and like us:

Leave a comment