Monday, February 5, 2018

Write a Qbasic 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.

Write a Qbasic 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 FAC(N)
CLS
INPUT "ENTER ANY NUMBER"; N
B = FAC(N)
PRINT "TOTAL NO. OF FACTORS="; B
PRINT "PRIME NUMBERS FROM 12 TO 35 ARE"
FOR J = 12 TO 35
    G = FAC(J)
    IF G = 2 THEN PRINT J
NEXT J
END
FUNCTION FAC (N)
FOR I = 1 TO N
    IF N MOD I = 0 THEN C = C + 1
NEXT I
FAC = C


END FUNCTION

2 comments: