Write a program in QBasic to print the even numbers between 1 to 50.
Answers
Hello there,
The following is quick and dirty, but it should do the trick :
10 REM ‘Program to find the sum of of even numbers between 10 and 50’
20 CLS
30 LET s = 10
40 FOR i = 10 TO 50 STEP 2
50 LET s = s + i
60 NEXT i
70 PRINT "The sum of the numbers is "; s
80 END
Now, this is an easy example, and should produce a string of even numbers of the simplest sort.
For sophistication, we can add this :
10 REM ‘Program to find the sum of of even numbers between 10 and 50’
15 REM ‘Using i MOD 2 form’
20 CLS
30 LET s = 10
40 FOR i = s TO 50
50 IF i MOD 2 =0 THEN LET s = s + i
60 NEXT i
70 PRINT "The sum of the numbers is "; s
80 END
Where the Modulus (MOD) of 2 for even numbers is used to return a more precise result. Also, we can modify value s to whatever we want.
We can get even more sophisticated by putting in INPUT statements to take in user inputs for variables s and i . And so on.
I must beg your pardon for using line numbers and bold text statements. Its just to show that at 40 years old I am a programming old codger, as I grew up programming Z80-class 8bit home computers like 1K RAM ZX-81’s, and 8088 1MB XT PC’s and GW-Basic !
Hope this helps.
Answer:
QBasic application that prints the even numbers between 1 and 50.
Explanation:
From the above question,
Here's a QBasic application that prints the even numbers between 1 and 50:
CLS
FOR i = two TO 50 STEP 2
PRINT i
NEXT i
L et's begin with the CLS statement. This assertion clears the display earlier than the application starts offevolved executing. It's no longer strictly necessary, however it ensures that the output of the software begins on a easy slate.
The FOR loop is the important good judgment of the program. It begins at two (FOR i = 2), increments via two on every new release (STEP 2), and stops at 50 (TO 50). This ability that i takes on the values 2, 4, 6, ..., 50.
Within the loop, we have a single statement: PRINT i. This declaration prints the present day fee of i on the screen. Since i is incremented by using two on every iteration, it will solely take on even values.
After the loop completes, the application ends. The stop end result is that the software prints out all the even numbers between 1 and 50 on the screen.
The FOR loop begins at 2, increments through two on every iteration, and stops at 50. The PRINT announcement prints the contemporary fee of i, which will be even for every generation of the loop. The CLS declaration clears the display earlier than the software starts.
For more such related questions : https://brainly.in/question/47966571
#SPJ2