Computer Science, asked by ishan428, 4 months ago

Write a program in QBASIC to print the first 6 terms of the following series: 2 4 16 256..........​

Answers

Answered by BrainlyProgrammer
2

➡️Question:-

  • Program to print first 6 terms

➡️Series:-

2 4 16 256....6th term

➡️Coding Language:- QBASIC

______________________

▶️Answer:-

This is a very easy Question, you just need to understand the logic of this series.

first term is 2

second term is the square of the first term i.e. 4=2²

third term is the square of the second term i.e. 16=4²

Fourth term is the square of the third term i.e. 256=16²

So we find that each term starting from the second term is the square of the previous term.

_____________________

▶️Here comes the code...

CLS

D=2

FOR I=1 TO 6

PRINT D+" "

D=D*D

NEXT I

END

__________________

▶️Variable Description:-

  1. D:- Local variable to calculate and print the terms
  2. I :- Loop variable

_________________

▶️Explaination:-

  • Initial value of D is 2
  • The program runs I loop from 1 to 6
  • In each iteration, D gets printed and is updated with square of its previous value
  • I loop gets updated with +1
  • Once I value becomes 7, Loop terminates.

__________________

▶️Output:-

  • 2 4 16 256
Answered by anindyaadhikari13
2

Required Answer:-

Question:

Write a program in QBASIC to print the first 6 terms of the series.

2 4 16 256...

Solution:

In this series, each term is the square of the previous terms. For example,

4 = 2²

16 = 4²

256 = 16²

Here comes the code.

CLS

DIM X AS INTEGER

X = 2

FOR I = 1 TO 6

PRINT X + " "

X=X*X

NEXT I

END

Dry Run:

When i = 1:

X = 2

Output: 2

Now, X = 2*2 = 4

When i = 2:

X = 4

Output: 4

Now, X = 4*4 = 16

In this way, the program works.

Similar questions