225k views
1 vote
What is the QBasic code for receiving the marks of 200 students using For.... NEXT loop and compute the average mark? Making your loop control variable initialize with value __________.

A. 0
B. 1
C. 200
D. "For.... NEXT"

User JohannesR
by
7.8k points

1 Answer

6 votes

Final answer:

To collect marks for 200 students in QBasic and compute the average, you should initialize the loop control variable with 1. The loop uses a FOR...NEXT structure to input and sum the marks, then computes the average by dividing the total sum by 200.

Step-by-step explanation:

To answer the question regarding the QBasic code for receiving the marks of 200 students and computing the average mark, you will want to initialize your loop control variable with the value 1, which corresponds to option B. Here's an example of how you might write the code:

DIM sum AS INTEGER
DIM marks AS INTEGER
DIM average AS SINGLE

sum = 0
FOR i = 1 TO 200
INPUT "Enter marks for student ", i, marks
sum = sum + marks
NEXT i

average = sum / 200
PRINT "The average mark is "; average

In this code, you're using a FOR...NEXT loop to collect the marks for each of the 200 students. As each mark is inputted, it's added to a running sum. After all marks have been collected, the code computes the average by dividing the sum by the number of students, which is 200.

User Lpacheco
by
8.4k points