Monday, October 11, 2021

QBASOC Program to print whether the given number is Prime or Composite

CLS
INPUT "Enter any Number "; n
FOR i = 1 TO n
     IF n MOD i = 0 THEN c = c + 1
NEXT i
IF c = 2 THEN
     PRINT "Prime Number"
ELSE
     PRINT "Composite Number"
END IF
END


Using SUB Procedure

DECLARE SUB Prime(n)
CLS
INPUT "Enter any number : "; n
CALL Prime(n)
END

SUB Prime (n)
FOR i = 1 TO n
     IF n MOD i = 0 THEN c = c + 1
NEXT i
IF c = 2 THEN
     PRINT "Prime Number"
ELSE
     PRINT "Composite Number"
END IF
END SUB


Using FUNCTION Procedure

DECLARE FUNCTION Prime(n)
CLS
INPUT "Enter any number : "; n
r = Prime(n)
IF r = 2 THEN
     PRINT "Prime Number"
ELSE
     PRINT "Composite Number"
END IF
END

FUNCTION Prime (n)
FOR i = 1 TO n
     IF n MOD i = 0 THEN c = c + 1
NEXT i
Prime = c
END FUNCTION

No comments:

Post a Comment

If you have any doubts, Please let me know.

[Download PDF] Computer Science Book Gread-10 in Nepali Language

 If you are searching for class 10 Computer Science in Nepali pdf for free download then you are at the right page. This book is soley publi...