MODULAR PROGRAMMING (EXERCISE 1)



##Program using SUB Procedure SUB…END SUB

#Write a program to input any two numbers and display their sum.

DECLARE SUM ADD(A,B)

CLS

INPUT “ENTER TWO NUMBERS”;A,B

CALL ADD (A,B)

END

SUB ADD (A,B)

SUM =A+B

PRINT “SUM OF TWO NUMBERS=”; SUM

END SUB

 

#WRITE A PROGRAM TO ENTER THE LENGTH AND BREADTH AND CALCULATE THE AREA OF RECTANGLE.

DECLARE SUB AREA(L,B)

INPUT “ENTER THE LENGTH AND BREADTH”; L,B

CALL AREA(L,B)

END

SUB AREA(L,B)

AR=L*B

PRINT “AREA OF RECTANGLE=”;AR

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE AREA OF FOUR WALLS. [A=2H(L+B)]

DECLARE SUB AREA(L,B)

CLS

INPUT “ENTER LENGTH, BREADTH AND HEIGHT”;(L,B,H)

CALL AREA (L,B,H)

END

SUB AREA (L,B,H)

A=2*H*(L+B)

PRINT “AREA OF FOUR WALLS=”;A

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE AVERAGE OF ANY THREE NUMBERS.

DECLARE SUB AVG(A,B,C)

CLS

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

CALL AVG(A,B,C)

END

SUB AVG(A,B,C)

AVERAGE=(A+B+C)/3

PRIN “AVERAGE OF THREE NUMBERS=”;AVERAGE

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE TOTAL DISTANCE TRAVELLED BY A BODY. [S=UT+(1/2)AT^2]

DECLARE SUB DISTANCE(U,T,A)

CLS

INPUT “ENTER INITIAL VELOCITY, TIME AND ACCELERATION”;U,T,A

CALL DISTANCE(U,T,A)

END

SUB DISTANCE(U,T,A)

S=(U*T)+(1/2)*A*T^2

PRINT “TOTAL DISTANCE TRAVELLED BY BODY=”;S

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE AREA AND CIRCUMFERENCE OF A CIRCLE.

DECLARE SUB CIRCLE(R)

CLS

INPUT “ENTER THE RADIUS”;R

CALL CIRCLE(R)

END

SUB CIRCLE(R)

AREA=(22/7)*R^2

CIRCUMFERENCE= 2*(22/7)*R

PRINT “AREA OF CIRCLE=”;AREA

PRINT “CIRCUMFERENCE OF CIRCLE=”;CIRCUMFERENCE

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE VOLUME OF SPHERE.

DECLARE SUB VOL(R)

CLS

INPUT “ENTER THE RADIUS”;R

CALL VOL(R)

END

SUB VOL(R)

V=(4/3)*(22/7)*R^3

PRINT “VOLUME OF SPHERE=”;V

END SUB

 

#WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST.

DECLARE SUB ABC(P,T,R)

CLS

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

CALL ABC(P,T,R)

END

SUB ABC(P,T,R)

SI=P*T*R

PRINT “SIMPLE INTEREST=”;SI

END SUB

 

#WRITE A PRGRAM TO INPUT TEMPERATURE IN CENTIGRADE AND CONVERT INTO FAHRENHEIT. [F=(9/5)*(C+32)]

DECLARE SUB TEM(C)

CLS

INPUT “ENTER TEMPERATURE IN CENTIGRADE”;C

CALL TEM(C)

END

SUB TEM(C)

F=(9/5)*(C+32)

PRINT “TEMPERATURE IN FAHRENHEIT IS=”;F

END SUB

 

#WAP TO CHECK WHETHER THE ENTERED NUMBER IS POSITIVE OR NEGATIVE.

DECLARE SUB CHECK(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL CHECK(N)

END

SUB CHECK(N)

IF N>0 THEN

PRINT “NUMBER IS POSITIVE”

ELSE

PRINT “NUMBER IS NEGATIVE”

END IF

END SUB

 

#WAP TO CHECK WHETHER THE ENTERED NUMBER IS DIVISIBLE BY 5 OR NOT.

DECLARE SUB CHECK(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL CHECK(N)

END

SUB CHECK(N)

IF N MOD 5=0 THEN

PRINT “NUMBER IS DIVISIBLE BY 5”

ELSE

PRINT “NUMBER IS NOT DIVISIBLE BY 5”

END IF

END SUB


Sujit Prasad Kushwaha

A Dedicated Blogger Sharing Insights and Making a Difference.

Post a Comment

The comment section is your chance to make your mark. Don't hold back - add to the discussion and let your personality shine through!

Previous Post Next Post