Full width home advertisement

Grade 10 Revision

Post Page Advertisement [Top]

Sub Procedure Programs

Sub Procedure Programs

 







1. WAP to accept degree in Celsius and convert it into Fahrenheit where F = (9/5)*C+32 using SUB.. END SUB.

DECLARE SUB CONVERT( C ) 

INPUT “ENTER DEGREE IN CELSIUS”; C

CALL CONVERT( C )

END

SUB CONVERT ( C )

F = (9/5)*C+32

PRINT “THE DEGREE IN FAHRENHEIT IS :”;F

END SUB 



2. Write a SUB program to check whether the supplied number is even or odd. 

DECLARE SUB CHECK(N)

INPUT "ENTER A NUMBER ";N

CALL CHECK(N)

END

SUB CHECK(N)

IF N MOD 2 = 0 THEN

    PRINT "IT IS EVEN"

    ELSE

    PRINT "IT IS ODD"

END IF

END SUB



3. Write a program to check whether the given number is positive, negative or zero using Sub… end sub.


DECLARE SUB CHECK(N)

INPUT "ENTER A NUMBER ";N

CALL CHECK(N)

END

SUB CHECK(N)

IF N > 0 THEN

    PRINT "IT IS POSITIVE"

    ELSEIF N<0 THEN

    PRINT "IT IS NEGATIVE"

ELSE

PRINT “IT IS ZERO”

END IF

END SUB



4. WAP to find simple interest using SUB…. END SUB

DECLARE SUB INTEREST( P, T , R ) 

INPUT “ENTER PRINCIPAL, TIME AND RATE ”; P, T , R 

CALL INTEREST( P, T , R )

END

SUB INTEREST( P, T , R )

I = ( P* T * R )/ 100

PRINT “THE SIMPLE INTEREST  IS :”;I

END SUB 



5. WAP to check whether the given year is leap year or not using SUB…. END… SUB

DECLARE SUB CHECK(Y)

INPUT "ENTER A YEAR ";Y

CALL CHECK(Y)

END

SUB CHECK(Y)

IF Y MOD 4 = 0 AND Y MOD  100 < > 0 OR Y MOD 4 = 0 THEN

    PRINT "IT IS LEAP YEAR"

    ELSE

    PRINT "IT IS NOT LEAP YEAR”

END IF

END SUB


6. WAP TO CHECK WHETHER THE GIVEN NUMBER IS PERFECT SQUARE OR NOT USING SUB END SUB.


DECLARE SUB PERFECT(N)

INPUT”ENTER A NUMBER”;N

CALL PERFECT(N)

END

SUB PERFECT(N)

S= SQR(N)

IF S = INT(S) THEN

PRINT N; “IS A PERFECT SQUARE”

ELSE

PRINT N; “IT IS NOT A PERFECT SQUARE”

END IF 

END SUB



7. WAP TO INPUT THREE SIDES OF A TRIANGLE AND DETERMINE WHETHER A TRIANGLE IS EQUILATERAL, ISOSECLES OR SCALENE TRAINGLE USING SUB PROCEDURE.


DECLARE SUB TRIANGLE(A,B,C)

INPUT “ENTER THREE SIDES OF TRIANGLE”;A,B,C

CALL TRIANGLE(A,B,C)

END

SUB TRIANGLE (A,B,C)

IF A = B AND B = C THEN 

PRINT “ IT IS EQUILATERAL TRAINGLE”

ELSEIF A= B OR B=C  OR C=A  THEN

PRINT” IT IS ISOSECLES TRAINGLE”

ELSE

PRINT”IT IS SCALENE TRAINGLE”

END IF 

END SUB 


8. WAP TO FIND THE GREATEST NUMBER AMONG THREE NUMBERS USING SUB END SUB.

DECLARE SUB CHECK(A,B,C)

INPUT “ENTER THREE NUMBERS”;A,B,C

CALL CHECK(A,B,C)

END

SUB CHECK (A,B,C)

IF A > B AND A > C THEN 

PRINT A; “IS THE LARGEST NUMBER”

ELSEIF B > A AND B > C  THEN

PRINT B; “IS THE LARGEST NUMBER”

ELSE

PRINT C; “IS THE LARGEST NUMBER”

END IF

END SUB















9. WAP to find the middle number among three different numbers using SUB.

DECLARE SUB MIDDLE ( A , B , C)  6,5,6

INPUT “ENTER THREE NUMBERS”; A,B,C

CALL MIDDLE (A, B , C)

END

SUB MIDDLE (A, B , C)

IF A > B AND A< C OR A < B AND A > C THEN

M = A

ELSEIF B > A AND B < C OR B < A AND B > C THEN

M = B

ELSE

M = C

END IF 

PRINT “THE MIDDLE NUMBER IS”; M

END SUB 



10. WAP TO INPUT RUPEES OR US DOLLAR. CONVERT IT INTO ANOTHER FORM USING THE FOLLOWING CONDITIONS:

IF INPUT IS IN RUPEES THEN CONVERT IT INTO US DOLLAR AND VICE VERSA.


DECLARE SUB CONVERT (V)

INPUT “ENTER RUPEES OR DOLLAR” ; DR

CALL CONVERT (DR)

END

SUB CONVERT(V)

PRINT “ TYPE R TO CONVERT INTO RUPEES”

PRINT “TYPE D TO CONVERT INTO DOLLAR”

INPUT”ENTER R OR D”; C$

IF UCASE$(C$) = “D” THEN

R = V/110

PRINT “RUPEES”;V; “=”;D;”DOLLARS”

ELSE

D = V*110

PRINT “DOLLARS”; V ; “=” ; D; “RUPEES”

END IF

END SUB



11. WAP using sub to display the multiplication table of a given number.


DECLARE SUB MUL(N)

INPUT”ENTER A NUMBER”;N

CALL MUL(N)

END

SUB MUL(N)

FOR I = 1 TO 10 

PRINT N; “X” ; I; “=”;N*I

NEXT I

END SUB


12. WAP TO PRINT THE POSSIBLE FACTORS OF GIVEN NUMBER USING SUB END SUB.


DECLARE SUB FACTOR(N)

INPUT “ENTER A NUMBER”;N

CALL FACTOR(N)

END 

SUB FACTOR(N)

PRINT” THE FACTORS OF”;N; “ARE”

FOR I = 1 TO N 

IF N MOD I =0 THEN PRINT I

NEXT I

END SUB 






13. WAP TO PRINT ALL THE PRIME FACTORS OF A GIVEN NUMBER USING SUB END SUB.


DECLARE SUB PRIME(N)

INPUT “ENTER A NUMBER”;N

CALL PRIME(N)

END

SUB PRIME(N)

PRINT “THE PRIME FACTORS OF”;N; “ARE”

FOR I =1 TO N

C=0

FOR J = 1 TO I

IF I MOD J =0 THEN C= C+1

NEXT J

IF N MOD I= 0 AND C=2 THEN PRINT I

NEXT I

END SUB



14. Wap to find the factorial of a given number using Sub End Sub.


DECLARE SUB FACT (N)     

INPUT”ENTER A NUMBER”;N

CALL FACT (N)

END

SUB FACT (N)

F=1

FOR I = 1 TO N

F = F* I

NEXT I 

PRINT “THE FACTORIAL OF”;N; “IS”; F

END SUB 

15. WAP TO PRINT THE FOLLOWING SERIES USING SUB END SUB.

1    4    7   10   13   UPTO 10th TERMS


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES 

A=1

FOR I = 1 TO 10

PRINT A;

A= A+3

NEXT I

END SUB




16. WAP TO PRINT THE FOLLOWING SERIES USING SUB.

10   20  30   ….. 100 


DECLARE SUB SERIES( )

CLS

CALL SERIES

END 

SUB SERIES

N=10

FOR I= 1 TO 10

P = N*I

PRINT P; 

NEXT I

END SUB 










17. WAP TO PRINT THE FOLLOWING SERIES:

30   28.5   27   25.5   UPTO 9TH TERMS


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

A=30

FOR I=1 TO 9

PRINT A;

A=A-1.5

NEXT I 

END SUB




18. WAP TO SUB PROGRAM TO PRINT THE FOLLOWING SERIES

1    121    12321   1234321    123454321


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

N#=1

FOR I=1 TO 5

PRINT N#^2;

N#= N#*10+1

NEXT I

END SUB 







19. WAP to print the following series using sub end sub.

3   6   12   24   upto 15th terms 


DECLARE SUB SERIES( )

CLS

CALL SERIES

END 

SUB SERIES

N= 3

FOR I=1 TO 15

PRINT N;

N= N*2

NEXT I

END SUB



20. WAP to print the following series using Sub… end sub.

6   9   18  21  42  upto 10th terms


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

N=6

FOR I =1 TO 10

PRINT N;

IF N MOD 2 = 0 THEN

N= N+3

ELSE

N=N*2

END IF 

NEXT I

END SUB 







21. WAP to print the following series using SUB… END ..SUB:

7    22    11   34   upto 10th terms.

(Note:This series is called Hailstone Series)


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

N=7

FOR I= 1 TO 10

PRINT N;

IF N MOD 2=0 THEN

N= N/2

ELSE

N= N*3+1

END IF

NEXT I

END SUB



22. WAP to print the following pattern using SUB… END SUB.

5

55

555

5555

55555


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

N=5

FOR I= 1 TO 5

PRINT N

N= N*10+5

NEXT I

END SUB


23. WAP to print the following pattern:

55555

5555     

555

55

5


DECLARE SUB SEIRES( )

CLS

CALL SERIES

END

SUB SERIES

N=55555

FOR I=1 TO 5

PRINT N

N=N\10

NEXT I

END SUB  



24. WAP a sub program to print the following series:

1

12

123

1234

12345


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

FOR I = 1 TO 5 

FOR J = 1 TO I

PRINT J;

NEXT J

PRINT

NEXT I 

END SUB 


25. WAP to print the following pattern using sub end .

12345

1234

123

12

1


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

FOR I = 5 TO 1 STEP-1

FOR J = 1 TO I

PRINT J;

NEXT J

PRINT

NEXT I

END SUB 





26. WAP to print the following pattern using SUB… END…SUB.

54321

5432

543

54

5

DECLARE SUB SERIES( )

CLS

CALL SERIES

END 

SUB SERIES

FOR I = 1 TO 5 

FOR J = 5 TO I STEP-1

PRINT J;

NEXT J

PRINT

NEXT I 

END SUB


27. WAP to print the following series using sub… end sub.

55555

4444

333

22

1


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

FOR I = 5 TO 1 STEP-1

FOR J = 1 TO I 

PRINT I;

NEXT J

PRINT

NEXT I

END SUB


28. WAP to print the following pattern using sub procedure.

1

22

333

4444

55555

DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

FOR I = 1 TO 5

FOR J = 1 TO I 

PRINT I;

NEXT J

PRINT

NEXT I

END SUB

29. WAP a program using sub procedure to print the following pattern

1

23

456

78910


DECLARE SUB SERIES( )

CLS

CALL SERIES

END

SUB SERIES

N=1

FOR I = 1 TO 4

FOR J = 1 TO I

PRINT N;

N=N+1

NEXT J

PRINT

NEXT I

END SUB 



30. WAP to print the following series using SUB… END.. .SUB.

1   1   2   3  5  upto 10th terms


DECLARE SUB FIB( )

CLS

CALL FIB

END

SUB FIB

A=1

B=1

PRINT A;B;

FOR I=1 TO 8

C= A+B

PRINT C;

A=B

B=C

NEXT I 

END SUB





31. WAP to check whether the given number is prime or composite using SUB.. .END… SUB


DECLARE  SUB CHECK(N)

INPUT”ENTER A NUMBER”;N

CALL CHECK(N)

END

SUB CHECK(N)

FOR I = 1 TO N

IF N MOD I =0 THEN 

C= C+1

END IF

NEXT I 

IF C=2 THEN

PRINT N; “ IS PRIME NUMBER”

ELSE

PRINT N; “IS COMPOSITE NUMBER”

END IF

END SUB 


32. WAP using sub procedure to display all the prime numbers from 1 to 100.

DECLARE SUB PRIME( )

CLS

CALL PRIME

END

SUB PRIME

FOR N=1 TO 100

FOR I= 1 TO N

IF N MOD I = 0 THEN C=C+1

NEXT I

IF C=2 THEN

PRINT N;

END IF

NEXT N

END SUB


33. WAP to find the HCF/GCD of two numbers using SUB…END SUB


DECLARE SUB HCF(A,B)

INPUT “ENTER TWO NUMBERS”;A,B

IF A>B THEN SWAP A,B

CALL HCF(A,B)

END

SUB HCF(A,B)

FOR I=1 TO A

IF A MOD I= 0 AND B MOD I=0 THEN

H=I

END IF

NEXT I

PRINT “THE HCF IS”;H

END SUB 


34. WAP to find the LCM of two numbers using SUB.. END…SUB.


DECLARE SUB LCM(A,B)

INPUT “ENTER TWO NUMBERS”;A,B

IF A>B THEN SWAP A,B

CALL LCM(A,B)

END

SUB LCM(A,B)

FOR I=1 TO A

IF A MOD I= 0 AND B MOD I=0 THEN

H=I

END IF

NEXT I

L= (A*B)/H

PRINT “THE LCM IS”;L

END SUB 








35. WAP to find the sum of digits of multidigit numbers using SUB….  END… SUB.


DECLARE SUB SUM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R= N MOD 10    

S=S+ R 

N=N\10   

WEND

PRINT “THE SUM OF DIGITS OF NUMBER IS”;S

END SUB 



36. WAP to find the product of digits of multidigit numbers using SUB….  END… SUB.

DECLARE SUB PRODUCT(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL PRODUCT(N)

END

SUB PRODUCT(N)

S=1

WHILE N<>0

R= N MOD 10    

S=S*R 

N=N\10   

WEND

PRINT “THE PRODUCT OF DIGITS OF NUMBER IS”;S

END SUB 



37. WAP to print the sum of all even digits in a given multidigit number using SUB… END…SUB


DECLARE SUB SUM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R= N MOD 10 

IF  R MOD 2=0 THEN

S=S+ R 

END IF

N=N\10   

WEND

PRINT “THE SUM OF EVEN DIGITS OF NUMBER IS”;S

END SUB 


38. WAP to print the sum of all odd digits in a given multidigit number using SUB.. END..SUB.


DECLARE SUB SUM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R= N MOD 10 

IF  R MOD 2<>0 THEN

S=S+ R 

END IF

N=N\10   

WEND

PRINT “THE SUM OF ODD DIGITS OF NUMBER IS”;S

END SUB 

39. WAP to find the sum of square of digits of multidigit number using SUB…END…SUB.


DECLARE SUB SUM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0   

R= N MOD 10 

S=S+ R^2 

N=N\10   

WEND

PRINT “THE SUM OF SQUARE OF DIGITS OF NUMBER IS”;S

END SUB


40. WAP to find the sum of cube of digits of multidigit number using Sub… End…Sub


DECLARE SUB SUM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0   

R= N MOD 10 

S=S+ R^3 

N=N\10   

WEND

PRINT “THE SUM OF CUBE OF DIGITS OF NUMBER IS”;S

END SUB 







41. WAP to enter a multidigit number and print it in reversed order using SUB.. END… SUB.


DECLARE SUB REV(N)   

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL REV(N)

END

SUB REV(N)

WHILE N<>0   

R= N MOD 10 

S=S*10+R 

N=N\10   

WEND

PRINT “THE REVERSED NUMBER IS”;S

END SUB 


42. WAP to check whether the multidigit number is palindrome or not using SUB.. END… SUB.


DECLARE SUB REV(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL REV(N)

END

SUB REV(N)

P=N

WHILE N<>0   

R= N MOD 10 

S=S*10+R 

N=N\10   

WEND

IF P= S THEN

PRINT “IT IS PALINDROME”

ELSE

PRINT “IT IS NOT PALINDROME”

END IF

END SUB 






43. WAP to check whether the multidigit number is Armstrong or not using SUB.. END… SUB.


DECLARE SUB ARM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL ARM(N)

END

SUB ARM(N)

P=N

WHILE N<>0   

R= N MOD 10 

S=S+ R^3 

N=N\10   

WEND

IF P= S THEN

PRINT “IT IS ARMSTRONG”

ELSE

PRINT “IT IS NOT ARMSTRONG”

END IF

END SUB 



44. WAP to print the longest word among three words using SUB… END… SUB. 


DECLARE SUB LONG(A$ , B$, C$)

INPUT “ENTER THREE WORDS”; A$ , B$, C$

CALL LONG(A$ , B$, C$)

END

SUB LONG(A$ , B$, C$)

P = LEN(A$)

Q = LEN(B$)

R = LEN(C$)

IF P >Q AND P>R THEN

PRINT A$’; “IS THE LONGEST WORD”

ELSEIF Q>P AND Q>R THEN

PRINT B$’; “IS THE LONGEST WORD”

ELSE

PRINT C$’; “IS THE LONGEST WORD”

END IF

END SUB






No comments:

Post a Comment

Bottom Ad [Post Page]