REM To find the product of first n natural numbers (Qbasic Code)
CLS
INPUT "Enter the number"; n
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
PRINT "The product upto"; n; "="; p
END
Using SUB Procedure
DECLARE SUB product (n)
CLS
INPUT "Enter the number"; n
CALL product(n)
END
SUB product (n)
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
PRINT "The product upto"; n; "="; p
END SUB
Using FUNCTION Procedure
DECLARE FUNCTION product (n)
CLS
INPUT "Enter the number"; n
PRINT product (n)
END
FUNCTION product (n)
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
product = p
END FUNCTION
CLS
INPUT "Enter the number"; n
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
PRINT "The product upto"; n; "="; p
END
Using SUB Procedure
DECLARE SUB product (n)
CLS
INPUT "Enter the number"; n
CALL product(n)
END
SUB product (n)
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
PRINT "The product upto"; n; "="; p
END SUB
Using FUNCTION Procedure
DECLARE FUNCTION product (n)
CLS
INPUT "Enter the number"; n
PRINT product (n)
END
FUNCTION product (n)
p = 1
FOR i = 1 TO n
p = p * i
NEXT i
product = p
END FUNCTION