QBASIC PROGRAM TO FIND PRIME OR COMPOSITE NUMBER

QBASIC PROGRAM TO FIND PRIME OR COMPOSITE NUMBER


2 = PRIME,4=COMPOSITE


CLS
 INPUT ENTER ANY NUMBER; N
 C = 0
 FOR I = 1 TO N
 IF N MOD I = 0 THEN C = C + 1
 NEXT I
 IF C < > 2 THEN
 PRINT N; IS COMPOSITE NUMBER
 ELSE
 PRINT N; IS PRIME OR NOT COMPOSITE NUMBER
 END IF
 END

Using Sub


DECLARE SUB COMPOSITE(N)
 CLS
 INPUT ENTER ANY NUMBER; N
 CALL COMPOSITE(N)
 END
 
 SUB COMPOSITE(N)
 C = 0
 FOR I = 1 TO N
 IF N MOD I = 0 THEN C = C + 1
 NEXT I
 IF C < > 2 THEN
 PRINT N; IS COMPOSITE NUMBER
 ELSE
 PRINT N; IS PRIME OR NOT COMPOSITE NUMBER
 END IF
 END SUB

Post a Comment

0 Comments