Wednesday, July 25, 2018

QBASIC Program Display Prime Number

QBASIC PROGRAM [ SEE / SLC NEPAL]
Q. Write a program to define a function procedure having a numeric parameter which returns total number of factors of a number and use the function in a program to display prime numbers from 12 to 35.

DECLARE FUNCTION FACTOR(N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = FACTOR(N)
PRINT "TOTAL NO. OF FACTORS"; A
PRINT "PRIME NUMBERS FROM 12 TO 35 ARE";
FOR J = 12 TO 35
    IF FACTOR(J) = 2 THEN PRINT J;
NEXT J
END

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


No comments:

Post a Comment