QBASIC PROGRAM TO CALCULATE SUM OF FIRST N NATURAL NUMBERS
CLS
INPUT “ENTER THE NUMBER”; N
S = N * (N + 1) / 2
PRINT “SUM OF”; N; “NUMBERS=”; S
END
USING SUB
DECLARE SUB SUM(N)
CLS
INPUT “ENTER THE NUMBER”; N
CALL SUM(N)
END
SUB SUM(N)
S = N * (N + 1) / 2
PRINT “SUM OF”; N; “NUMBERS=”; S
END SUB
0 Comments