Saturday, October 22, 2016

Qbasic Program: Check Odd or Even Number



81. WAP to input any number and check whether the given no. is divisible by 5 or not.
REM
CLS
INPUT “ENTER ANY NUMBER”; N
IF N MOD 5 = 0 THEN
PRINT N; "IS DIVISIBLE BY 5”
ELSE
PRINT N; "IS NOT DIVISIBLE BY 5”
END IF
END
USING SUB PROCEDURE
DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N MOD 5 = 0 THEN
PRINT N; "IS DIVISIBLE BY 5”
ELSE
PRINT N; "IS NOT DIVISIBLE BY 5”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N) ; “BY 5”
END
FUNCTION CHECK$ (N)
IF N MOD 5 = 0 THEN
CHECK$ = “DIVISIBLE”
ELSE
CHECK$ = “NOT DIVISIBLE”
END IF : END FUNCTION




82.   WAP to input any number and check whether the given no. is divisible by 3 and 7 or not.
REM
CLS
INPUT “ENTER ANY NUMBER”; N
IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
PRINT N; "IS COMPLETELY DIVISIBLE BY 3 AND 7”
ELSE
PRINT N; "IS NOT COMPLETELY DIVISIBLE BY 3 AND 7”
END IF
END
USING SUB PROCEDURE
DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
PRINT N; "IS COMPLETELY DIVISIBLE BY 3 AND 7”
ELSE
PRINT N; "IS NOT COMPLETELY DIVISIBLE BY 3 AND 7”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N) ; “BY 3 AND 7”
END
FUNCTION CHECK$ (N)
IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
CHECK$ = “DIVISIBLE”
ELSE
CHECK$ = “NOT DIVISIBLE”
END IF : END FUNCTION
83.   WAP to input any number and check whether the given no. is positive, negative or zero.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N > 0 THEN
PRINT N; "IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; "IS NEGATIVE NUMBER”
ELSE
PRINT N; "IS ZERO”
END IF
END
USING SUB PROCEDURE
DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N > 0 THEN
PRINT N; "IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; "IS NEGATIVE NUMBER”
ELSE
PRINT N; "IS ZERO”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N)
END
FUNCTION CHECK$ (N)
IF N > 0 THEN
CHECK$ = “POSITIVE NUMBER”
ELSEIF N < 0 THEN
CHECK$ = “NEGATIVE NUMBER”
ELSE
CHECK$ = “ZERO”
END IF : END FUNCTION
84.   WAP to input a year and display whether that year is a leap year or not. [divisible by 4 but not 100]
REM
CLS
INPUT “ENTER YEAR”; Y
IF Y MOD 4 = 0 AND Y MOD 100 <> 0 OR Y MOD 400 = 0 THEN
PRINT Y; "IS LEAP YEAR”
ELSE
PRINT Y; "IS NOT LEAP YEAR”
END IF
END
USING SUB PROCEDURE
DECLARE SUB CHECK (Y)
CLS
INPUT “ENTER YEAR”; Y
CALL CHECK (Y)
END
SUB CHECK (Y)
IF Y MOD 4 = 0 AND Y MOD 100 <> 0 OR Y MOD 400 = 0 THEN
PRINT Y; "IS LEAP YEAR”
ELSE
PRINT Y; "IS NOT LEAP YEAR”
END IF
END SUB

DECLARE FUNCTION CHECK$ (Y)
CLS
INPUT “ENTER YEAR”; Y
PRINT Y; CHECK$(Y)
END
FUNCTION CHECK$ (Y)
IF Y MOD 4 = 0 AND Y MOD 100 <> 0 OR Y MOD 400 = 0 THEN
CHECK$ = “IS LEAP YEAR”
ELSE
CHECK$ = “IS NOT LEAP YEAR”
END IF
END FUNCTION
85.   WAP to input any number and display whether it is odd or even.
      REM
      CLS
      INPUT “ENTER ANY NUMBER”; N
      IF N MOD 2 = 0 THEN
      PRINT N; “IS EVEN NUMBER”
ELSE
PRINT N; “IS ODD NUMBER”
END IF
END

DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END

SUB CHECK (N)
IF N MOD 2 = 0 THEN
      PRINT N; “IS EVEN NUMBER”
ELSE
PRINT N; “IS ODD NUMBER”
END IF
END SUB

DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N)
END

FUNCTION CHECK$ (N)
IF N MOD 2 = 0 THEN
CHECK$ = “EVEN NUMBER”
ELSE
CHECK$ = “ODD NUMBER”
END IF
END

86. To divide a number by another number and find the quotient and remainder.

CLS
INPUT "ENTER FIRST NUMBER"; A
INPUT "ENTER SECOND NUMBER"; B
IF A > B THEN
R = A MOD B
Q = A \ B
ELSE
R = B MOD A
Q = B \ A
END IF
PRINT "QUOTIENT="; Q
PRINT "REMAINDER ="; R
END
USING SUB PROCEDURE

DECLARE SUB DIVIDE (A, B)
CLS
INPUT "ENTER FIRST NUMBER"; A
INPUT "ENTER SECOND NUMBER"; B
CALL DIVIDE (A, B)
END

SUB DIVIDE (A, B)
IF A > B THEN
R = A MOD B
Q = A \ B
ELSE
R = B MOD A
Q = B \ A
END IF
PRINT "QUOTIENT="; Q
PRINT "REMAINDER ="; R
END SUB




87.   WAP to input any number and check whether the given no. is positive or negative.

REM
CLS
INPUT “ENTER ANY NUMBER”; N
IF N > 0 THEN
PRINT N; IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; IS NEGATIVE NUMBER”
END IF
END

USING SUB PROCEDURE

DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N > 0 THEN
PRINT N; "IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; "IS NEGATIVE NUMBER”
END IF
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N)
END
FUNCTION CHECK$ (N)
IF N > 0 THEN
CHECK$ = “POSITIVE NUMBER”
ELSEIF N < 0 THEN
CHECK$ = “NEGATIVE NUMBER”
END IF
END FUNCTION
88. Input a mark in a subject of a student and check if the student is pass or nor. [Pass Mark >=40]

REM
CLS
INPUT “ENTER MARKS”; M
IF M >= 40 THEN
PRINT “YOU ARE PASS”
ELSE
PRINT “ YOU ARE FAIL”
END IF
END

USING SUB PROCEDURE
DECLARE SUB CHECK (M)
CLS
INPUT “ENTER MARKS”; M
CALL CHECK (M)
END
SUB CHECK (N)
IF M >= 40 THEN
PRINT “YOU ARE PASS”
ELSE
PRINT “ YOU ARE FAIL”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (M)
CLS
INPUT “ENTER MARKS”; M
PRINT “YOU ARE “;CHECK$(M)
END

FUNCTION CHECK$ (M)
IF M >= 40 THEN
CHECK$ =“PASS”
ELSE
CHECK$ = “FAIL”
END IF
END FUNCTION
89. Input the age of a person and find out whether the person is eligible to drive or not. [age >=16]

REM
CLS
INPUT “ENTER YOUR AGE”; A
IF A >= 16 THEN
PRINT “YOU ARE ELIGIBLE TO DRIVE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO DRIVE”
END IF
END
USING SUB PROCEDURE

DECLARE SUB CHECK (A)
CLS
INPUT “ENTER YOUR AGE”; A
CALL CHECK (A)
END

SUB CHECK (A)
IF A >= 16 THEN
PRINT “YOU ARE ELIGIBLE TO DRIVE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO DRIVE”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (A)
CLS
INPUT “ENTER YOUR AGE”; A
PRINT “YOU ARE “;CHECK$(A)
END
FUNCTION CHECK$ (A)
IF A >= 16 THEN
CHECK$ = “ELIGIBLE TO DRIVE”
ELSE
CHECK$ = “ NOT ELIGIBLE TO DRIVE”
END IF
END FUNCTION
90. Input the age of a person and find out whether the person is eligible to vote or not. [age >=18]
REM
CLS
INPUT “ENTER YOUR AGE”; A
IF A >= 18 THEN
PRINT “YOU ARE ELIGIBLE TO VOTE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO VOTE”
END IF
END

USING SUB PROCEDURE

DECLARE SUB CHECK (A)
CLS
INPUT “ENTER YOUR AGE”; A
CALL CHECK (A)
END

SUB CHECK (A)
IF A >= 18 THEN
PRINT “YOU ARE ELIGIBLE TO VOTE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO VOTE”
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (A)
CLS
INPUT “ENTER YOUR AGE”; A
PRINT “YOU ARE “;CHECK$(A)
END
FUNCTION CHECK$ (A)
IF A >= 18 THEN
CHECK$ = “ELIGIBLE TO VOTE”
ELSE
CHECK$ = “ NOT ELIGIBLE TO VOTE”
END IF
END FUNCTION
91. WAP to enter any 15 numbers and display only those numbers which are divisible by 5.

CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
PRINT "THE NUMBERS WHICH ARE DIVISIBLE BY 5 ARE"
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 THEN PRINT N(I)
NEXT I
END

USING SUB PROCEDURE
DECLARE SUB DIVISIBLE (N( ))
CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL DIVISIBLE (N ( ))
END
SUB DIVISIBLE (N ( ))
PRINT "THE NUMBERS WHICH ARE DIVISIBLE BY 5 ARE"
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 THEN PRINT N(I)
NEXT I
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION DIVISIBLE (N( ))
CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
D = DIVISIBLE(N())
END

FUNCTION DIVISIBLE (N())
PRINT "THE NUMBERS DIVISIBLE BY 5 ARE";
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 THEN PRINT N(I)
NEXT I

END FUNCTION

92.   WAP to enter any 15 numbers and display only those numbers which are divisible by 5 and 7.
CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
PRINT "THE NUMBERS WHICH ARE DIVISIBLE BY 5 AND 7 ARE"
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 AND N(I) MOD 7 = 0 THEN PRINT N(I)
NEXT I
END
USING SUB PROCEDURE
DECLARE SUB DIVISIBLE (N( ))
CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL DIVISIBLE (N ( ))
END
SUB DIVISIBLE (N ( ))
PRINT "THE NUMBERS WHICH ARE DIVISIBLE BY 5 AND 7 ARE"
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 AND N(I) MOD 7 = 0 THEN PRINT N(I)
NEXT I
END SUB
USING FUNCTION PROCEDURE

DECLARE FUNCTION DIVISIBLE (N( ))
CLS
DIM N(15)
FOR I = 1 TO 15
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
D = DIVISIBLE(N( ))
END

FUNCTION DIVISIBLE (N( ))
PRINT "THE NUMBERS DIVISIBLE BY 5 AND 7 ARE";
FOR I = 1 TO 15
IF N(I) MOD 5 = 0 AND N(I) MOD 7 = 0 THEN PRINT N(I)
NEXT I

END FUNCTION


8 comments:

  1. this will be helpful for students and old mans :)

    ReplyDelete
  2. this blog should be so good that nobody can resist it even old mans and wamens on the street of goldilocks drinking beer and vodka

    ReplyDelete
  3. wow so many comments and so good blog this blog should be awarded an oscar nice blog so good blog wowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww :)

    ReplyDelete
  4. Thank u ☺
    It make my work easier ☺☺

    ReplyDelete