Solution of FUNCTION Procedure2
1. Using FUNCTION...END FUNCTION , write a program to calculate distance travelled by a body.[Hint: S=ut+1/2at^2]
DECLARE FUNCTION distance (u, t, a)
CLS
INPUT "Enter an initial velocity"; u
INPUT "Enter time taken"; t
INPUT "Enter acceleration"; a
PRINT "The distance travelled is "; distance(u, t, a)
END
FUNCTION distance (u, t, a)
distance = u * t + 1 / 2 * a * t ^ 2
END FUNCTION
2. Write a program using Function module to calculate and print the volume of a box.
DECLARE FUNCTION volume (l, b, h)
CLS
INPUT "Enter length"; l
INPUT "Enter breadth"; b
INPUT "Enter height"; h
PRINT "The volume of box is "; volume(l, b, h)
END
FUNCTION volume (l, b, h)
volume = l * b * h
END FUNCTION
3. Write a program using FUNCTION...END FUNCTION to find the average of any two numbers given by the users.
DECLARE FUNCTION average (a, b)
CLS
INPUT "Enter first number"; a
INPUT "Enter second number"; b
PRINT "Average is "; average(a, b)
END
FUNCTION average (a, b)
average = (a + b) / 2
END FUNCTION
4. Write a program using FUNCTION...END FUNCTION to find the average of any three numbers given by the users.
DECLARE FUNCTION average (a, b,c)
CLS
INPUT "Enter first number"; a
INPUT "Enter second number"; b
INPUT "Enter third number"; c
PRINT "Average is "; average(a, b,c)
END
FUNCTION average (a, b,c)
average = (a + b+c) / 3
END FUNCTION
DECLARE FUNCTION distance (u, t, a)
CLS
INPUT "Enter an initial velocity"; u
INPUT "Enter time taken"; t
INPUT "Enter acceleration"; a
PRINT "The distance travelled is "; distance(u, t, a)
END
FUNCTION distance (u, t, a)
distance = u * t + 1 / 2 * a * t ^ 2
END FUNCTION
2. Write a program using Function module to calculate and print the volume of a box.
DECLARE FUNCTION volume (l, b, h)
CLS
INPUT "Enter length"; l
INPUT "Enter breadth"; b
INPUT "Enter height"; h
PRINT "The volume of box is "; volume(l, b, h)
END
FUNCTION volume (l, b, h)
volume = l * b * h
END FUNCTION
3. Write a program using FUNCTION...END FUNCTION to find the average of any two numbers given by the users.
DECLARE FUNCTION average (a, b)
CLS
INPUT "Enter first number"; a
INPUT "Enter second number"; b
PRINT "Average is "; average(a, b)
END
FUNCTION average (a, b)
average = (a + b) / 2
END FUNCTION
4. Write a program using FUNCTION...END FUNCTION to find the average of any three numbers given by the users.
DECLARE FUNCTION average (a, b,c)
CLS
INPUT "Enter first number"; a
INPUT "Enter second number"; b
INPUT "Enter third number"; c
PRINT "Average is "; average(a, b,c)
END
FUNCTION average (a, b,c)
average = (a + b+c) / 3
END FUNCTION
Comments