Write a q basic program input five integer numbers count how many numbers are divisible by five ? with the help of loop command .
I don't know how to solve it i tried but I'm getting errors
CodePudding user response:
Here is a sample QBasic program that inputs five integer numbers and counts how many numbers are divisible by five using a loop command:
' Program to input five integer numbers and count how many numbers are divisible by five
' Define a variable to hold the number of numbers that are divisible by five
DIM count AS INTEGER
' Define a variable to hold the input number
DIM number AS INTEGER
' Set the initial value of the count variable to zero
count = 0
' Use a FOR loop to input the five numbers
FOR i = 1 TO 5
' Input the current number
INPUT "Enter a number: ", number
' Check if the number is divisible by five
IF number MOD 5 = 0 THEN
' If the number is divisible by five, increment the count
count = count 1
END IF
NEXT i
' Output the result
PRINT count; " of the numbers are divisible by five."
In this program, the count
variable is used to keep track of how many numbers are divisible by five. The number
variable is used to hold the input number. A FOR loop is used to input the five numbers, and for each number, the program checks if it is divisible by five using the MOD
operator. If the number is divisible by five, the count
variable is incremented. After the FOR loop completes, the program outputs the final value of the count
variable, which represents the number of numbers that are divisible by five.