Wednesday, October 16, 2019

73. Qbasic program to input number and check whether the given no. is prime or composite.


73.      Write a function program to input number and check whether the given no. is prime or composite.

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 COMPOSITE 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

No comments:

Post a Comment