QBasic Programming

WAP to input number and check whether the given no. composite 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 COMPOSITE NUMBER"
ELSE
PRINT N; "IS NOT COMPOSITE NUMBER"
END IF
END

USING SUB PROCEDURE

DECLARE SUB COMPOSITE (N)
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 NOT COMPOSITE NUMBER"
END IF
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION COMPOSITE (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CO = COMPOSITE (N)
IF CO < > 2 THEN
PRINT N; "IS COMPOSITE NUMBER"
ELSE
PRINT N; "IS NOT COMPOSITE NUMBER"
END IF
END

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

WAP to input number and check whether the given no. is prime or not (Prev Lesson)
(Next Lesson) WAP to input any number and display the factors
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!