SUB PROCEDURE Numeric Patterns and Series

MORE PROGRAM RELATED TO SUB PROCEDURE (CLICK HERE)

MORE PROGRAMS RELATED TO FUNCTIONS (CLICK HERE)

MORE PROGRAMS RELATED TO NUMERIC PATTERN IN QBASIC (CLICK HERE)

MORE PROGRAMS RELATED TO STRING PATTERN IN QBASIC (CLICK HERE)

———————————————————————————————————————————————-

Print the series using SUB PROCEDURE 7   22   11   34   17   52   26   13   40   20

DECLARE SUB series()

CALL series

END

SUB series

a = 7

FOR i = 1 TO 10

PRINT a;

IF a MOD 2 = 0 THEN

a = a \ 2

ELSE

a = a * 3 + 1

END IF

NEXT

END SUB

Print the following series: 1, 8, 27, 64,  …….. up to 10th terms using SUB procedure.

Ans:

DECLARE SUB SERIES()

CLS

CALL SERIES

END

SUB SERIES

FOR I =  1 TO 10

PRINT I^3;

NEXT I

END SUB

Display the series 55555, 5555, 555, 55, 5.

Ans:

DECLARE SUB SERIES()

CLS

CALL SERIES

END

SUB SERIES

A#= 55555

FOR I = 1TO 5

PRINT A#;

A#=A#\10

NEXT I

END SUB

Define SUB procedure to display the following series of number: 1, 1, 2, 3, 5, …..up to 13thterm.

Ans:

DECLARE SUB SERIES()

CLS

CALL SERIES

END

SUB SERIES

A=1

B=1

PRINT A;B;

FOR I =1 TO 11

C=A+B

PRINT C;

A=A+B

B=A+B

NEXT I

END SUB

Generate the series using SUB …… END SUB : -10, -8, -6, -4, ………. Up to 20th term.

Ans:

DECLARE SUB SERIES()

CLS

CALL SERIES

END

SUB SERIES

A=-10

FOR I = 1 TO 20

PRINT A;

A=A+2

NEXT I

END SUB

Display Numeric Patterns using SUB PROCEDURE    2    22     222     2222      22222 [Hint: insert (;) in PRINT to print horizontally Eg. PRINT a;]

DECLARE SUB result()

CALL result

END

SUB result

CLS

a = 2

FOR i = 1 TO 5

PRINT a

a = a * 10 + 2

NEXT

END SUB

Display using SUB PROCEDURE  1      121     12321      1234321      123454321    [Hint: insert (;) in PRINT to print horizontally Eg. PRINT a*a; ]

DECLARE SUB PATTERN()
CALL PATTERN
END
SUB PATTERN
CLS
DEFDBL A

a = 1
FOR i = 1 TO 5
PRINT a * a
a = a * 10 + 1
NEXT
END SUB

Display  using SUB PROCEDURE     123454321         1234321          12321        121           1    [Hint: insert (;) in PRINT to print horizontally Eg. PRINT a*a; ]

DECLARE SUB PATTERN()

CALL PATTERN

END

SUB PATTERN

DEFDBL A

a = 11111

WHILE a <> 0

PRINT a * a

a = a \ 10

WEND

END SUB

Display using SUB PROCEDURE    1      12      123      1234     12345

1

12

123

1234

12345

DECLARE SUB PATTERN()
CALL PATTERN
END
SUB PATTERN
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT j;
NEXT
PRINT
NEXT
END SUB

Display using SUB PROCEDURE  12345     1234    123     12   1

12345

1234

123

12

1

DECLARE SUB PATTERN()
CALL PATTERN
END
SUB PATTERN
FOR i = 5 TO 1 STEP -1
FOR j = 1 TO i
PRINT j;
NEXT
PRINT
NEXT
END SUB

Display    using SUB PROCEDURE 55555     4444     333    22     1

55555

4444

333

22

1

DECLARE SUB PATTERN()
CALL PATTERN
END
SUB PATTERN
FOR i = 5 TO 1 STEP -1
FOR j = 1 TO i
PRINT i;
NEXT
PRINT
NEXT
END SUB

Display using SUB PROCEDURE      *****1.00           ****11.00          ***111.00            **1111.00               *11111.00

*****1.00

****11.00

***111.00

**1111.00

*11111.00

DECLARE SUB pattern()
CALL pattern
END
SUB pattern
CLS
a = 1
FOR i = 1 TO 5
PRINT USING “**######.##”; a
a = a * 10 + 1
NEXT i
END SUB

Display using SUB PROCEDURE     1      22     333     4444     55555  

1

22

333

4444

55555

DECLARE SUB PATTERN()
CALL PATTERN
END
SUB PATTERN
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT i;
NEXT
PRINT
NEXT
END SUB

Write a sub program to display numbers 2, 4, 6, …………..20

DECLARE SUB DIS ()
CALL DIS
END

SUB DIS
FOR P = 2 TO 20 STEP 2
PRINT P;
NEXT P
END SUB

Write a sub program to display numbers 100, 90, 80, — 10 using DO— LOOP WHILE statement.

DECLARE SUB DISP ()
CALL DISP
END

SUB DISP
CLS
A = 100
DO
PRINT A;
A = A – 10
LOOP WHILE A >= 10
END SUB

Write a sub program to display numbers 30, 28.5, 27, 25.5, — 9th terms using DO — LOOP until statement.

DECLARE SUB DISP ()
CALL DISP
END

SUB DISP
CLS
N = 30
P = 1
DO
PRINT N;
N = N – 1.5
P = P + 1
LOOP UNTIL P > 9
END SUB

Write a sub program to display numbers -10, -5, 0, 5, 10, — 12th  terms using DO UNTIL — LOOP statement.

DECLARE SUB NDISP ()
CALL NDISP
END

SUB NDISP
CLS
A = -10
C = 1
DO UNTIL C > 12
PRINT A
A = A + 5
C = C + 1
LOOP
END SUB

Write a sub program to display numbers 1, 8, 27, — 10th  terms using DO — WHILE LOOP statement

DECLARE SUB CUBE ()
CALL CUBE
END

SUB CUBE
CLS
C = 1
DO
PRINT C ^ 3
C = C + 1
LOOP WHILE C <= 10
END SUB

Write SUB program of   1        12        123         1234          12345

1

12

123

1234

12345

DECLARE SUB PATTERN ()
CLS
CALL PATTERN
END
SUB PATTERN
FOR I = 1 TO 5
FOR J = 1 TO I
PRINT J;
NEXT J
PRINT
NEXT I
END SUB

Write SUB program of 55555     4444     333    22       1

55555

4444

333

22

1

DECLARE SUB PATT ()
CLS
CALL PATT
END

SUB PATT
FOR K = 5 TO 1 STEP -1
FOR J = 1 TO K
PRINT K;
NEXT J
PRINT
NEXT K
END SUB

Write SUB program   5    54     543     5432      54321

5

54

543

5432

54321

DECLARE SUB PAT ()
CLS
CALL PAT
END

SUB PAT
FOR I = 5 TO 1 STEP -1
FOR J = 5 TO I STEP -1
PRINT J;
NEXT J
PRINT
NEXT I
END SUB

Write SUB program  1   10    101     1010     10101

1

10

101

1010

10101

DECLARE SUB SERIES ()
CLS
CALL SERIES
END

SUB SERIES
FOR I = 1 TO 5
FOR J = 1 TO I
PRINT J MOD 2;
NEXT J
PRINT
NEXT I
END SUB

Write SUB program   88888888      666666     4444    22

88888888

666666

4444

22

DECLARE SUB PATT ()
CLS
CALL PATT
END

SUB PATT
T = 10
FOR K = 8 TO 1 STEP -2
PRINT TAB(T);
FOR J = 1 TO K
PRINT K;
NEXT J
PRINT
T = T + 3
NEXT K
END SUB

Write SUB program   13579    1357    135   13   1

1 3 5 7 9

1 3 5 7

1 3 5

1 3

1

DECLARE SUB NUM ()
CLS
CALL NUM
END

SUB NUM
FOR K = 9 TO 1 STEP -2
FOR J = 1 TO K STEP 2
PRINT J;
NEXT
PRINT
NEXT
END SUB

Write SUB program     123456789       1234567     12345     123     1

123456789

1234567

12345

123

1

DECLARE SUB PATTERN ()
CLS
CALL PATTERN
END

SUB PATTERN
A# = 123456789
C = 1
WHILE C <= 5
PRINT TAB(C); A#
A# = A# \ 100
C = C + 1
WEND
END SUB

Write SUB program    pattern

40

38 40

36 38 40

32 34 36 38 40

34 36 38 40

DECLARE SUB PATT ()
CLS
CALL PATT
END

SUB PATT
X = 40
FOR P = 1 TO 5
Y = X
FOR Q = 1 TO P
PRINT Y;
Y = Y + 2
NEXT Q
PRINT
X = X – 2
NEXT P
END SUB

Write SUB program

70 65 60 55 50

70 65 60 55

70 65 60

70 65

70

DECLARE SUB NPAT ()
CLS
CALL NPAT
END
SUB NPAT
A = 50
B = 70
FOR X = A TO B STEP 5
FOR Y = B TO X STEP -5
PRINT Y;
NEXT Y
PRINT
NEXT X
END SUB

Write SUB program   2, 4, 8, 16 … 12th terms

DECLARE SUB SERIES ()
CLS
CALL SERIES
END

SUB SERIES
P = 2
N = 1
DO WHILE N <= 12
PRINT P;
P = P * 2
N = N + 1
LOOP
END SUB

Write SUB program   2, 3, 5, 8, 13 — up to 10th terms.

DECLARE SUB SER ()
CLS
CALL SER
END

SUB SER
A = 2
B = 3
FOR I = 1 TO 10
PRINT A;
C = A + B
A = B
B = C
NEXT I
END SUB

Write SUB program  11, 3, 14, 17, 31, — 18th

DECLARE SUB SERI ()
CLS
CALL SERI
END

SUB SERI
A = 11
B = 3
P = 1
WHILE P <= 18
PRINT A;
C = A + B
A = B
B = C
P = P + 1
WEND
END SUB

Write SUB program 1, 4, 9, — UP TO 9th terms

DECLARE SUB SQUARE ()
CLS
CALL SQUARE
END

SUB SQUARE
FOR K = 1 TO 9
A = K ^ 2
PRINT A;
NEXT K
END SUB