WAP IN QBASIC to print the sum of first 10 even number
Answers
Answered by
3
Required Answer:-
Question:
- Write a program in QBASIC to print the sum of first ten even numbers.
Solution:
Here is the QBASIC program.
CLS
c = 2
S = 0
FOR I = 1 TO 10 STEP 1
S = S + c
c = c + 2
NEXT I
PRINT "Sum of first ten even numbers is: "; S
END
Explanation:
- The loop iterates 10 times. After each iteration, the value of c is added to the sum and value of c is incremented by 2 to get the next even number. At last, we will display the result.
Output is attached.
Attachments:
Similar questions