To check the given number is divisible by 4 or not (Qbasic Code)
CLS
INPUT "Enter a number"; n
x = n MOD 4
IF x = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END
CLS
INPUT "Enter a number"; n
CALL check(n)
END
SUB check (n)
x = n MOD 4
IF x = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END SUB
CLS
INPUT "Enter a number"; n
a$ = check$(n)
PRINT a$
END
FUNCTION check$ (n)
x = n MOD 4
IF x = 0 THEN
ans$ = "The given number is exactly divisible by 4"
ELSE
ans$ = "The given number is not exactly divisible by 4"
END IF
check$ = ans$
END FUNCTION
CLS
INPUT "Enter a number"; n
IF check(n) = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END
FUNCTION check (n)
x = n MOD 4
check = x
END FUNCTION
CLS
INPUT "Enter a number"; n
x = n MOD 4
IF x = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END
- Using SUB Procedure
CLS
INPUT "Enter a number"; n
CALL check(n)
END
SUB check (n)
x = n MOD 4
IF x = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END SUB
- Using FUNCTION Procedure
CLS
INPUT "Enter a number"; n
a$ = check$(n)
PRINT a$
END
FUNCTION check$ (n)
x = n MOD 4
IF x = 0 THEN
ans$ = "The given number is exactly divisible by 4"
ELSE
ans$ = "The given number is not exactly divisible by 4"
END IF
check$ = ans$
END FUNCTION
- Using FUNCTION Procedure (Alternate Method)
CLS
INPUT "Enter a number"; n
IF check(n) = 0 THEN
PRINT "The given number is exactly divisible by 4";
ELSE
PRINT "The given number is not exactly divisible by 4";
END IF
END
FUNCTION check (n)
x = n MOD 4
check = x
END FUNCTION