QBasic Programming

WAP to input number and check whether the given no. 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 PROCEDURE

DECLARE SUB PRIME (N)
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 PROCEDURE

DECLARE FUNCTION PRIME(N)
CLS
INPUT "ENTER ANY NUMBER"; N
P = PRIME (N)
IF P = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS NOT PRIME NUMBER"
END IF
END

FUNCTION PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
PRIME = C
END FUNCTION

WAP to display first 15 prime numbers (Prev Lesson)
(Next Lesson) WAP to input number and check whether the given no. composite or not
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!