Solution of FUNCTION Procedure

1. Write a program to calculate the volume of a cylinder using FUNCTION...END FUNCTION.

DECLARE FUNCTION volume(r,h)
CLS
INPUT "Enter radius of a cylinder";r
INPUT "Enter height of a cylinder";h
PRINT "Volume of a cylinder is ";volume(r,h)
END

FUNCTION volume(r,h)
v=22/7*r^2*h
volume=v
END FUNCTION

2. Write a program to declare user defined function to count total number of  alphabet 'A' occurred in a  given string where string is passed as a parameter.[use FUNCTION...END FUNCTION.]

DECLARE FUNCTION countA(S$)
CLS
INPUT "Enter a string";S$
PRINT "Total number of alphabet  A is " ;countA(S$)
END

FUNCTION countA(S$)
FOR I=1 TO LEN(S$)
C$=UCASE$(MID$(S$,I,1))
IF C$="A" THEN
c=c+1
END IF
NEXT I
countA=c
END FUNCTION

3. Write a program to print the middle number among the three different number using FUNCTION...END FUNCTION.

DECLARE FUNCTION middle(A,B,C)
CLS
INPUT "Enter a first number";A
INPUT "Enter second number";B
INPUT "Enter third number";C
PRINT "The middle number is ";middle(A,B,C)
END

FUNCTION middle(A,B,C)
IF (A<B AND A>C) OR (A>B AND A<C) THEN
m=A
ELSE IF (B<A AND B>C)OR(B>A AND B<C) THEN
m=B
ELSE
M=C
END IF
middle=m
END FUNCTION

4. Write a program to find the factorial number of any number using FUNCTION...END FUNCTION.

DECLARE FUNCTION factorial(N)
CLS
INPUT "Enter a number";N
PRINT "The factorial is ";factorial(N)
END

FUNCTION factorial(N)
f=1
for I=1 TO N
f=f*I
NEXT I
factorial=f
END FUNCTION

5. Write a program to read any character and check whether the entered character is vowel or consonant using FUNCTION...END FUNCTION.

DECLARE FUNCTION  checkVC$(C$)
INPUT "Enter a character";C$
PRINT checkVC$(C$)
END

FUNCTION checkVC$(C$)
CL$=UCASE$(C$)
AC=ASC(CL$)
IF CL$="A" OR CL$="E" OR CL$="I" OR CL$="O" OR CL$="U" THEN
checkVC$="It is a vowel letter"
 ELSE IF AC<>65 AND  AC<>69 AND AC<>73 AND AC<>79 AND  AC<>85 AND ( AC>=65 AND AC<=90) THEN
checkVC$="It is a consonant letter"
END IF
END FUNCTION

Comments

Anonymous said…
We love u...keep on posting.😁

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