Printing Series in QBASIC (SET-1)
QBASIC Programs to print series using different Looping Statements
1) 5, 25, 125, 625, 3125 .... up to 7th terms.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
a = 5
FOR i = 1 TO 7
PRINT a;
a = a * 5
NEXT i
END
|
CLS
a = 5
i = 1
WHILE i <= 7
PRINT a;
a = a * 5
i = i + 1
WEND
END
|
CLS
a = 5
i = 1
DO WHILE i <= 7
PRINT a;
a = a * 5
i = i + 1
LOOP
END
|
2) 1, 4, 9, 16, 25 .... up to 10th term.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
FOR i = 1 TO 10
PRINT i ^ 2;
NEXT i
END
|
CLS
i = 1
WHILE i <= 10
PRINT i ^ 2;
i = i + 1
WEND
END
|
CLS
i = 1
DO WHILE i <= 10
PRINT i ^ 2;
i = i + 1
LOOP
END
|
3) 1, 8, 27, 64, 125 ... up to 10th term.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
FOR i = 1 TO 10
PRINT i ^ 3;
NEXT i
END
|
CLS
i = 1
WHILE i <= 10
PRINT i ^ 3;
i = i + 1
WEND
END
|
CLS
i = 1
DO WHILE i <= 10
PRINT i ^ 3;
i = i + 1
LOOP
END
|
4) 1, 27, 125, 343, 729
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 1
FOR i = 1 TO 5
PRINT n ^ 3;
n = n + 2
NEXT i
END
|
CLS
n = 1
i = 1
WHILE i <= 5
PRINT n ^ 3;
n = n + 2
i = i + 1
WEND
END
|
CLS
n = 1
i = 1
DO
PRINT n ^ 3;
n = n + 2
i = i + 1
LOOP WHILE i <= 5
END
|
5) 1000, 500, 250, 125, 62.5
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 1000
FOR i = 1 TO 5
PRINT n;
n = n / 2
NEXT i
END
|
CLS
n = 1000
i = 1
WHILE i <= 5
PRINT n;
n = n / 2
i = i + 1
WEND
END
|
CLS
n = 1000
i = 1
DO
PRINT n;
n = n / 2
i = i + 1
LOOP WHILE i <= 5
END
|
6) 10, 8, 6, 4, 2
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
FOR i = 10 TO 1 STEP -2
PRINT i;
NEXT i
END
|
CLS
i = 10
WHILE i >= 1
PRINT i;
i = i - 2
WEND
END
|
CLS
i = 10
DO WHILE i >= 1
PRINT i;
i = i - 2
LOOP
END
|
7) 1, 3, 5, 7, 9 ...... 25
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
FOR i = 1 TO 25 STEP 2
PRINT i;
NEXT i
END
|
CLS
i = 1
WHILE i <= 25
PRINT i;
i = i + 2
WEND
END
|
CLS
i = 1
DO
PRINT i;
i = i + 2
LOOP UNTIL i >= 25
END
|
8) 0, 2, 4, 6, 8 ...... up to 100
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
FOR i = 0 TO 100 STEP 2
PRINT i;
NEXT i
END
|
CLS
i = 0
WHILE i <= 100
PRINT i;
i = i + 2
WEND
END
|
CLS
i = 0
DO WHILE i <= 100
PRINT i;
i = i + 2
LOOP
END
|
9) 5, 125, ... up to 7th term.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 5
FOR i = 1 TO 7
PRINT n;
n = n ^ 3
NEXT i
END
|
CLS
n = 5
i = 1
WHILE i <= 7
PRINT n;
n = n ^ 3
i = i + 1
WEND
END
|
CLS
n = 5
i = 1
DO WHILE i <= 7
PRINT n;
n = n ^ 3
i = i + 1
LOOP
END
|
10) 0.1, 0.11, 0.111 .... up to 7th term.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
a = 0.1
FOR i = 1 TO 7
PRINT a;
a = a / 10 + 0.1
NEXT i
END
|
CLS
a = 0.1
i = 1
WHILE i <= 7
PRINT a;
a = a / 10 + 0.1
i = i + 1
WEND
END
|
CLS
a = 0.1
i = 1
DO
PRINT a;
a = a / 10 + 0.1
i = i + 1
LOOP WHILE i <= 7
END
|
11) 5, 55, 555 .... up to 7th terms.
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 5
FOR i = 1 TO 7
PRINT n;
n = n * 10 + 5
NEXT i
END
|
CLS
n = 5
i = 1
WHILE i <= 7
PRINT n;
n = n * 10 + 5
i = i + 1
WEND
END
|
CLS
n = 5
i = 1
DO WHILE i <= 7
PRINT n;
n = n * 10 + 5
i = i + 1
LOOP
END
|
12) 3333333, 333333, 33333, 3333 .... 3
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 3333333
FOR i = 1 TO 7
PRINT n;
n = n \ 10
NEXT i
END
|
CLS
n = 3333333
i = 1
WHILE i <= 7
PRINT n;
n = n \ 10
i = i + 1
WEND
END
|
CLS
n = 3333333
i = 1
DO WHILE i <= 7
PRINT n;
n = n \ 10
i = i + 1
LOOP
END
|
13) 0.11111, 0.1111, 0.111 .... 0.1
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 0.11111
FOR i = 1 TO 5
PRINT n;
n = n * 10 - 1
NEXT i
END
|
CLS
n = 0.11111
i = 1
WHILE i <= 5
PRINT n;
n = n * 10 - 1
i = i + 1
WEND
END
|
CLS
n = 0.11111
i = 1
DO WHILE i <= 5
PRINT n;
n = n * 10 - 1
i = i + 1
LOOP
END
|
14) 1, 1, 2, 3, 5, 8 ... up to 10th term. (Fibonacci Series)
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
x = 1
y = 1
PRINT x; y;
FOR i = 1 TO 10
z = x + y
PRINT z;
x = y
y = z
NEXT i
END
|
CLS
x = 1
y = 1
i = 1
PRINT x; y;
WHILE i <= 10
z = x + y
PRINT z;
x = y
y = z
i = i + 1
WEND
END
|
CLS
x = 1
y = 1
i = 1
PRINT x; y;
DO WHILE i <= 10
z = x + y
PRINT z;
x = y
y = z
i = i + 1
LOOP
END
|
15) 3, 10, 5, 16, 8 (Hill-stone Number).
FOR ... NEXT |
WHILE ... WEND |
DO ... LOOP |
CLS
n = 3
FOR i = 1 TO 5
PRINT n;
IF n MOD 2 = 0 THEN
n = n / 2
ELSE
n = n * 3 + 1
END IF
NEXT i
END
|
CLS
n = 3
i = 1
WHILE i <= 5
PRINT n;
IF n MOD 2 = 0 THEN
n = n / 2
ELSE
n = n * 3 + 1
END IF
i = i + 1
WEND
END
|
CLS
n = 3
i = 1
DO WHILE i <= 5
PRINT n;
IF n MOD 2 = 0 THEN
n = n / 2
ELSE
n = n * 3 + 1
END IF
i = i + 1
LOOP
END
|
Javascript DisablePlease Enable Javascript To See All Widget
Post a Comment