How to do average programs in qbasic?

1 answer

Answer

1194758

2026-07-10 23:20

+ Follow

To calculate the average of a set of numbers in QBasic, you first need to declare variables to store the sum and count of the numbers. You can use a loop to input the numbers, adding each one to the sum and incrementing the count. After the loop, divide the total sum by the count to get the average. Here’s a simple example:

<code class="language-qbasic">DIM sum AS SINGLE

DIM count AS INTEGER sum = 0 count = 0

DO INPUT "Enter a number (or -1 to finish): ", num IF num <> -1 THEN sum = sum + num count = count + 1 END IF LOOP UNTIL num = -1

IF count > 0 THEN PRINT "Average: "; sum / count ELSE PRINT "No numbers entered." END IF

</code>
ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.