QBASIC PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR NOT
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 PRIME NUMBER
ELSE
PRINT N; IS NOT PRIME NUMBER
END IF
END
USING SUB
DECLARE SUB PRIME(N)
CLS
INPUT ENTER ANY NUMBER; N
CALL PRIME(N)
END
SUB PRIME(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 PRIME NUMBER
ELSE
PRINT N; IS NOT PRIME NUMBER
END IF
END SUB
USING FUNCTION
DECLARE FUNCTION PRIME$(N)
CLS
INPUT ENTER ANY NUMBER; N
PRINT N;
END
FUNCTION PRIME$(N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRIME$="IS PRIME NUMBER"
ELSE
PRIME$="IS NOT PRIME NUMBER"
END IF
END FUNCTION
0 Comments