Write a q basic program to print the sum of first five natural numbers.
Answers
Answered by
7
CLS
N = 0
FOR I = 1 TO 5
N = N+I
NEXT I
PRINT "SUM = ";N
END
Answered by
1
Required Answer:-
Question:
- Write a QBASIC program to print the sum of first 5 natural numbers.
Solution:
Here comes the program.
10 CLS
20 LET S=0
30 FOR I = 1 TO 5 STEP 1
40 S = S + I
50 NEXT I
60 PRINT "Sum: "
70 PRINT S
80 STOP
Explanation:
- Line 10: Clears the screen.
- Line 20: Declares sum = 0.
- Line 30: Iterates a loop in the range I = 1 to 5.
- Line 40: Adds the value of I to Sum.
- Line 50: End of loop.
- Line 60: Displays message.
- Line 70: Displays the sum.
- Line 80: End of program.
Similar questions
History,
2 months ago
Social Sciences,
2 months ago
English,
4 months ago
Social Sciences,
4 months ago
Science,
10 months ago
Social Sciences,
10 months ago
English,
10 months ago