write a program in qbasic to print the series 7,26, 63
Answers
QUESTION:-
- TO PRINT THE SERIES
_____________
Series:-
- 7,26,63...N
_____________
Logic:-
- i^3-1
_____________
Code:-
CLS
PRINT"ENTER NUMBER OF TERMS"
INPUT N
FOR I=2 TO N
PRINT ((I^3) -1)
NEXT I
END
Question:
Write a program in QBASIC to display the following series.
0 7 26 63.....N terms.
Program:
This is an easy question. Read this post to get your answer.
Here is the program.
CLS
INPUT "ENTER THE NUMBER OF TERMS - "; N
PRINT "Here is your series....."
FOR I = 1 TO N STEP 1
PRINT (I^3 - 1) + " "
NEXT I
PRINT "Program finished..."
END
Logic:
0 = 1³ - 1
7 = 2³ - 1
26 = 3³ - 1
Hence, nth term of the series is n³ - 1
In this program, we have created a loop and then calculated each term of the series and it is displayed.
Syntax of for loop:
FOR <VARIABLE> = <INITIAL_VALUE> TO <FINAL_VALUE> STEP <STEP_VALUE>
statements
.
.
NEXT <VARIABLE>
In this program, I is the variable, initial value is 1 and the final value is n. Step value is 1.