Topics

Search This Blog

Monday, March 17, 2025

'COMBINED' Modular programming solutions

 Modular programming solutions


1. Program to calculate perimeter and area of a rectangle. Use sub procedure to calculate perimeter and function procedure to calculate area.

DECLARE SUB PERI (L, B)

DECLARE FUNCTION AREA (L, B)

CLS

INPUT "Enter length and breadth="; L, B

CALL PERI (L, B)

A = AREA (L, B)

PRINT "Area of the rectangle="; A

END

SUB PERI (L, B)

P = 2 * (L + B)

PRINT "Perimeter of the rectangle="; P

END SUB

FUNCTION AREA (L, B)

AREA = L * B

END FUNCTION


2.  Calculate Simple Interest (Sub) and Compound Interest (Function)

DECLARE SUB SI (P, R, T)

DECLARE FUNCTION CI (P, R, T)

CLS

INPUT "Enter Principal, Rate, and Time="; P, R, T

CALL SI (P, R, T)  

C = CI (P, R, T)   

PRINT "Compound Interest="; C

END

SUB SI (P, R, T)

SI = (P * R * T) / 100

PRINT "Simple Interest="; SI

END SUB

FUNCTION CI (P, R, T)

CI = P * (1 + R / 100) ^ T - P

END FUNCTION


3. Calculate Area (Sub) and Circumference (Function) of a Circle

DECLARE SUB AREA(R)

DECLARE FUNCTION CIRCUM(R)

CLS

INPUT "Enter Radius of Circle="; R

CALL AREA (R)   

C = CIRCUM (R) 

PRINT "Circumference of the circle="; C

END

SUB AREA (R)

A = 3.1416 * R * R

PRINT "Area of the circle="; A

END SUB

FUNCTION CIRCUM(R)

CIRCUM = 2 * 3.1416 * R

END FUNCTION


4. Calculate Fahrenheit (Sub) and Kelvin (Function) from Celsius

DECLARE SUB FAHRENHEIT(C)

DECLARE FUNCTION KELVIN(C)

CLS

INPUT "Enter Temperature in Celsius="; C

CALL FAHRENHEIT(C)  

K = KELVIN(C)       

PRINT "Temperature in Kelvin="; K

END

SUB FAHRENHEIT(C)

F = (C * 9 / 5) + 32

PRINT "Temperature in Fahrenheit="; F

END SUB

FUNCTION KELVIN(C)

KELVIN = C + 273.15

END FUNCTION


5. Calculate Square Root (Sub) and Cube Root (Function)

DECLARE SUB SQRT_NUM(N)

DECLARE FUNCTION CUBE_ROOT(N)

CLS

INPUT "Enter a Number="; N

CALL SQRT_NUM(N) 

C = CUBE_ROOT(N) 

PRINT "Cube Root="; C

END

 

SUB SQRT_NUM(N)

S = SQR(N)

PRINT "Square Root="; S

END SUB

 

FUNCTION CUBE_ROOT(N)

CUBE_ROOT = N ^ (1 / 3)

END FUNCTION


6. Calculate Square Root (Sub) and Cube Root (Function)

DECLARE SUB SMALL(A, B)

DECLARE FUNCTION LARGE(A, B)

CLS

INPUT "Enter two numbers: "; A, B

CALL SMALL(A, B)   

G = LARGE(A, B)    

PRINT "Greater number="; G

END

SUB SMALL(A, B)

IF A < B THEN

    PRINT "Smaller number="; A

ELSE

    PRINT "Smaller number="; B

END IF

END SUB

 

FUNCTION LARGE(A, B)

IF A > B THEN

    LARGE = A

ELSE

    LARGE = B

END IF

END FUNCTION

7.  Calculate multiply(Sub) and addition (Function)

DECLARE FUNCTION Add(a, b)

DECLARE SUB Mul(a,b)

s = Add(a,b)

PRINT "Enter two numbers:"; s

CALL Mul(r)

 

FUNCTION Add(a, b)

Ans = a + b

Ad=Ans

END FUNCTION

 

SUB Mul(a,b)

M=a*b

PRINT "The multiplication is "; M

END SUB

8. SUB PROCEDURE TO DISPLAY 2, 4, 5, 8, 10.

 DECLARE SUB PATTERN(N)

 CALL PATTERN

 END

 

SUB PATTERN

 A=2

 FOR I=1 TO 5

 PRINT A;

 A=A+2

 NEXT I

 END SUB

9. SUB PROGRAM TO CALCULATE AREA AND FUNCTION PROGRAM TO CALCULATE VOLUME OF A ROOM.

DECLARE SUB ARE(L, B)

DECLARE FUNCTION VOL(L, B, H)

CLS

INPUT "Enter length, breadth and height="; L, B, H

CALL ARE(L, B)

Vo = VOL(L, B, H)

PRINT "Volume="; Vo

END

 

SUB ARE(L, B)

AR = L * B

PRINT "Area of a room="; AR

END SUB

 

FUNCTION VOL(L, B, H)

VOL = L * B * H

END FUNCTION


No comments:

Post a Comment

Map of Nepal

 नेपालको नक्सा:  नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा: नेपालको नक्सा:

Most viewed!