QBasic Programming

WAP to input any number and display the prime factorial of a given number

CLS
INPUT "ENTER ANY NUMBER"; N
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
PRINT "PRIME FACTORIAL ="; F
END

USING SUB PROCEDURE

DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END

SUB FACT (N)
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
PRINT "PRIME FACTORIAL ="; F
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "PRIME FACTORIAL ="; FACT (N)
END

FUNCTION FACT (N)
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
FACT = F
END FUNCTION

WAP to input any number and display the factorial of a given number (Prev Lesson)
(Next Lesson) WAP TO CHECK WHETHER THE INPUT NUMBER IS PERFECT NUMBER OR NOT
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!