Solution of Sub Procedure

1.  write a program to declare a sub procedure to generate multiplication table of a number,where number is passed as a parameter.[Use SUB...END SUB].
DECLARE SUB mulTable (N)
CLS
INPUT "Enter a number"; N
CALL mulTable(N)
END

SUB mulTable (N)
FOR i = 1 TO 10
PRINT N; "*"; i; "="; N * i
NEXT
END SUB

2. write a program to define sub procedure to print prime numbers from 1 to 500 using sub procedure
DECLARE SUB prime ()
CLS
prime
END

SUB prime
FOR I = 2 TO 500
FOR j = 2 TO I / 2
flag = 0
r = I MOD j
IF r = 0 THEN
flag = 1
EXIT FOR
 END IF
NEXT j
IF flag = 0 THEN
PRINT I,
END IF

NEXT I
END SUB

3.  Write a progrm to test whether the given number is positive or negative using SUB.......END SUB
DECLARE SUB PN (n)
CLS
INPUT "Enter a number "; n
PN n
END

 SUB PN (n)
IF n > 0 THEN
PRINT n; " is positive number"
ELSE
PRINT n; " is negative number"
END IF
END SUB

4. write a program to read any digits of a number and display it in reverse order by using SUB...END SUB
DECLARE SUB reverse (N)
CLS
INPUT "Enter a number"; N
CALL reverse(N)

END

SUB reverse (N)
N$ = STR$(N)
FOR I = LEN(N$) TO 1 STEP -1
R$ = R$ + MID$(N$, I, 1)
NEXT
R = VAL(R$)
PRINT "The reverse number of "; N; " is"; R

END SUB

5.  write a program to print the following series 1,8,27,64 ,........upto 10  terms using sub procedures
DECLARE SUB seriesCube ()
CLS
seriesCube
END

SUB seriesCube
FOR i = 1 TO 10
PRINT i ^ 3; ",";
NEXT i
END SUB

6. write a program to display the series 111111,11111,1111,111,11,1 by using SUB...END SUB
DECLARE SUB series ()
CLS
series
END

SUB series
FOR i = 6 TO 1 STEP -1
k = 1
FOR j = 1 TO i
PRINT k;
NEXT j
PRINT
NEXT i
END SUB

Comments

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PALINDROME AND ARMSTRONG PROGRAMS

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS