MODULAR PROGRAMMING (EXERCISE 5)


 

##PROGRAMMING USING FUNCTION PROCEDURE: FUNCTION…END FUNCTION

#WRITE A PROGRAM TO ADD ANY THREE NUMBERS USING FUNCTION PROCEDURE.

DECLARE FUNCCTION SUM(A,B,C)

CLS

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

PRINT “SUM=”;SUM(A,B,C)

END

FUNCTION SUM(A,B,C)

S=A+B+C

SUM=S

END FUNCTION

 

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

DECLARE FUNCTION AVG(A,B,C)

CLS

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

PRINT “AVERAGE IS=”;AVG(A,B,C)

END

FUNCTION AVG(A,B,C)

X=(A+B+C)/3

AVG=X

END FUNCTION

 

#WRITE A PROGRAM TO CALCULATE THE AREA OF FOUR WALLS USING FUNCTION PROCEDURE.

DECLARE FUNCTION AREA(H,L,B)

CLS

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

PRINT “AREA IS”;AREA(H,L,B)

END

FUNCTION AREA(H,L,B)

A=2*H*(L+B)

AREA=A

END FUNCTION

 

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

DECLARE FUNCTION DIS(U,T,A)

CLS

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

PRINT “DISTANCE TRAVELLED IS=”;DIS(U,T,A)

END

FUNCTION DIS(U,T,A)

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

DIS=S

END FUNCTION

 

#WRITE A PROGRAM TO CALCULATE THE TSA OF CUBOID. [TSA=2(LB+BH+LH)]

DECLARE FUNCTION CUBOID(L,B,H)

CLS

INPUT “ENTER LENGTH, BEADTH, HEIGHT”;L,B,H

PRINT “TSA OF CUBOID IS”;CUBOID(L,B,H)

END

FUNCTION CUBOID(L,B,H)

TSA=2*(L*B+B*H+L*H)

CUBOID=TSA

END FUNCTION

 

#WRITE A PROGRAM TO CALCULATE THE AREA OF CIRCLE USING FUNCTION PROCEDURE.

DECLARE FUNCTION AREA(R)

CLS

INPUT “ENTER RADIUS”;R

PRINT “AREA OF CIRCLE”;AREA(R)

END

FUNCTION AREA(R)

A=(22/7)*R^2

AREA=A

END FUNCTION

 

#WRITE A PROGRAM TO CALCULATE THE VOLUME OF SPHERE USING FUNCTION PROCEDURE.

DECLARE FUNCTION VOL(R)

CLS

INPUT “ENTER RADIUS”;R

PRINT “VOLUME OF SPHERE”;VOL(R)

END

FUNCTION VOL(R)

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

VOL=V

END FUNCTION

 

#WRITE A PROGRAM TO CONVERT THE TEMPERATURE INPUTTED IN CELSIUS INTO FARHENHEIT.

DECLARE FUNCTION TEM(C)

CLS

INPUT “TEMPERATURE IN CELSIUS”;C

PRINT “TEMPERATURE IN FAHRENHEIT”;TEM(C)

END

FUNCTION TEM(C)

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

TEM=F

END FUNCTION

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS ODD OR EVEN.

DECLARE FUNCTION OE$(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT OE$(N)

END

FUNCTION OE$(N)

IF N MOD 2=0 THEN

RESULT$=”EVEN”

ELSE

RESULT$=”ODD”

END IF

OE$=RESULT$

END FUNCTION

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS DIVISIBLE BY 13 OR NOT USING FUNCTION PROCEDURE.

DECLARE FUNCTION DIV$(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT DIV$(N)

END

FUNCTION DIV$(N)

IF N MOD 13=0 THEN

RESULT$=”DIVISIBLE”

ELSE

RESULT$=”NOT DIVISIBLE”

END IF

DIV$=RESULT$

END FUNCTION

 

#WRITE A PROGRAM TO PRINT THE FOLLOWING PATTERN:

A

AN

AND

ANDR

ANDRO

ANDROI

ANDROID

ANS:

DECLARE FUNCTION PATTERN$(A$,I”

CLS

A$= “ANDROID”

FOR I=1 TO LEN(A$)

PRINT PATTERN$(A$,I)

NEXT I

END

FUNCTION PATTERN$(A$,I)

PATTERN$=LEFT$(A$,I)

END FUNCTION

 

#WRITE A PROGRAM USING FUNCTION…END FUNCTION TO FIND SUM, PRODUCT AND DIFFERENCE OF TWO NUMBERS.

DECLARE FUNCTION SUM(A,B)

DECLARE FUNCTION PROD(A,B)

DECLARE FUNCTION DIFF(A,B)

CLS

INPUT “ENTER TWO NUMBERS”;A,B

PRINT “SUM OF TWO NUMBERS=”;SUM(A,B)

PRINT “PRODUCT OF TWO NUMBERS=”;PROD(A,B)

PRINT “DIFFERENCE OF TWO NUMBER=”;DIFF(A,B)

END

FUNCTION SUM(A,B)

S=A+B

SUM=S

END FUNCTION

FUNCTION PROD(A,B)

P=A*B

PROD=P

END FUNCTION

FUNCTION DIFF(A,B)

D=A-B

DIFF=D

END FUNCTION

 

#WRITE A PROGRAM TO PRINT THE STRING IN REVERSE ORDER.

DECLARE FUNCTION REV$(A$)

CLS

INPUT “ENTER ANY STRING”;A$

PRINT “THE REVEVRSED STRING IS=”;REV$(A$)

END

FUNCTION REV$(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)+B$

NEXT I

REV$=B$

END FUNCTION

 

#WRITE A PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER USING FUNCTION PROCEDURE.

DECLARE FUNCTION FAC(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT FAC(N)

END

FUNCTION FAC(N)

F=1

FOR I=1 TO N

F=F*I

NEXT I

FAC=F

END FUNCTION

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED STRING IS A PALINDROME OR NOT.

DECLARE FUNCTION PAL$(A$)

CLS

INPUT “ENTER ANY STRING”;A$

PRINT PAL$(A$)

END

FUNCTION PAL$(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)+B$

NEXT I

IF A$=B$ THEN

RESULT$= “STRING IS PALINDROME”

ELSE

RESULT$= “STRING IS NOT PALINDROME”

END IF

PAL$=RESULT$

END FUNCTION

 

#WRITE A PROGRAM TO PRINT THE FIBONACCI SERIES UPTO 10TH TERMS USING FUNCTION PROCEDURE.

DECLARE FUNCTIOON FIBO(A,B)

CLS

A=1

B=1

PRINT A;B;

FOR I=1 TO 8

C=FIBO(A,B)

PRINT C;

A=B

B=C

NEXT I

END

FUNCTION FIBO(A,B)

FIBO=A+B

END FUNCTION 

 

OR,

DECLARTE FUNCTION FIBO$()

CLS

ANS$=FIBO$

PRINT ANS$

END

FUNCTION FIBO$()

A=1

B=1

ANS$=STR$(A)+STR$(B)

FOR I=1 TO 8

C=A+B

ANS$=ANS$+STR$(C)

A=B

B=C

NEXT I

FIBO$=ANS$

END FUNCTION

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF VOWELS PRESENT IN A STRING USING FUNCTION PROCEDURE.

DECLARE FUNCTION  VOW(A$)

CLS

INPUT “ENTER ANY STRING”;A$

PRINT “TOTAL NUMBER OF VOWELS=”;VOW(A$)

END

FUNCTION VOW(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “A”, “E”, “I”, “O”, “U”

V=V+1

END SELECT

NEXT I

VOW=V

END FUNCTION

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF CONSONANTS PRESENT IN A STRING USING FUNCTION PROCEDURE.

DECLARE FUNCTION CON(A$)

CLS

INPUT “ENTER ANY STRING”;A$

PRINT “TOTAL NUMBER OF CONSONANTS”;CON(A$)

END

FUNTION CON(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

IF C$<> “O” AND C$<> “E” AND C$<> “I” AND C$<> “O” AND C$<> “U”

THEN

C=C+1

END IF

NEXT I

CON=C

END FUNCTION

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF CHARACTERS PRESENT IN A STRING.

DECLARE FUNCTION COUNT(N$)

CLS

INPUT “ENTER ANY STRING”;N$

PRINT “TOTAL NUMBER OF CHARACTERS”;COUNT(N$)

END

FUNCTION COUNT(N$)

FOR I=1 TO LEN(N$)

C=C+1

NEXT I

COUNT=C

END FUNCTION

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBERS OF WORDS PRESENT IN A STRING USING FUNCTION PROCEDURE.

DECLARE FUNCTION COUNT(N$)

CLS

INPUT “ENTER ANY STRING”;N$

PRINT “TOTAL NUMBER OF WORDS”;COUNT(N$)

END

FUNCTION COUNT(N$)

W=1

FOR I=1 TO LEN(N$)

B$=MID$(N$,I,1)

IF B$= “ ” THEN W=W+1

NEXT I

COUNT=W

END FUNCTION

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PALINDROME OR NOT USING FUNCTION PROCEDURE.

DECLARE FUNCTION PAL$(A)

CLS

INPUT “ENTER ANY NUMBER”;A

PRINT PAL$(A)

END

FUNCTION PAL$(A)

N=A

WHILE N<>0

R=N MOD 10

S=S*10+R

N=N\10

WEND

IF A=S THEN

RESULT$= “PALINDROME”

ELSE

RESULT$= “NOT PALINDROME”

END IF

PAL$=RESULT$

END FUNCTION

 

#WRITE A PROGRAM TO CALCULATE THE SUM OF A DIGITS OF A NUMBER USING FUNCTION PROCEDURE.

DECLARE FUNCTION SUM(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT “SUM OF DIGITS”;SUM(N)

END

FUNCTION SUM(N)

WHILE N<>0

R=N MOD 10

S=S+R

N=N\10

WEND

SUM=S

END FUNCTION

 

#WRITE A PROGRAM TO FIND THE SQUARE ROOT OF GIVEN NUMBER USING FUNCTION PROCEDURE.

DECLARE FUNCTION SQUARE(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT “SQUARE ROOT=”;SQUARE(N)

END

FUNCTION SQUARE(N)

SQ=N^(1/2)

SQUARE =SQ

END FUNCTION

 

#WRITE A PROGRAM TO FIND THE GREATEST DIGIT OF ANY NUMBER [FOR EXAMPLE, N=725, MAX=7] USING FUNCTION PROCEDURE.

DECLARE FUCNTION MAX(N)

CLS

INPUT “ENTER ANY NUMBEER”;N

PRINT “GREATEST DIGIT=”;MAX(N)

END

FUNCTION MAX(N)

MAXIMUM=0

DO WHILE N>0

R=N MOD 10

IF R>MAXIMUM THEN

MAXIMUM=R

LOOP

MAX=MAXIMUM

END FUNCTION

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF VOWELS AND CONSONANTS IN A STRING USING FUNCTION PROCEDURE.

DECLARE FUNCTION VOW(A$)

DECLARE FUNCTION CON(A$)

CLS

INPUT “ENTER ANY STRING”;A$

PRINT “TOTAL NUMBER OF VOWELS=”;VOW(A$)

PRINT “TOTAL NUMBER OF CONSONANTS=”;CON(A$)

END

FUNTION VOW(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “A”, “E”, “I”, “O”, “U”

V=V+1

END SELECT

NEXT I

VOW=V

END FUNCTION

FUNCTION CON(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

IF C$<> “A” AND C$<> “E” AND C$<> “I” AND C$<> “O” AND C$<> “U” THEN

C=C+1

END IF

NEXT I

CON=C

END FUNCTION

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PRIME OR COMPOSITE USING FUNCTION PROCEDURE.

DECLARE FUNCTION CHECK$(N)

CLS

INPUT “ENTER ANY NUMBER”;N

PRINT CHECK$(N)

END

FUNCTION CHECK$(N)

FOR I=1 TO N

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

NEXT I

IF C=2 THEN

RESULT$= “THE NUMBER IS PRIME”

ELSE

RESULT$= “THE NUMBER IS COMPOSITE”

END IF

CHECK$=RESULT$

END FUNCTION


 


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