Computer Science, asked by chandrikabagchi69, 8 days ago

Savita wants to write program to check whether a number is even or odd. bort find the remainder​

Answers

Answered by srivastavaanusha63
1

Answer:

Program using IF..ELSE

CLS

INPUT "Enter a Number: ", n

IF n MOD 2 = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END

Program using only IF

CLS

INPUT "Enter a Number:

Explanation:

n MOD 2 = 0 THEN

PRINT "Input Number is Even"

END IF

IF n MOD 2 = 1 THEN

PRINT "Input Number is Odd"

END IF

END

Program using Select Case

CLS

INPUT "Enter a Number: ", n

SELECT CASE (n MOD 2)

CASE 1

PRINT "Input Number is Odd"

CASE 0

PRINT "Input Number is EVEN"

END SELECT

END

Program using subroutine

DECLARE SUB odd_even

CLS

odd_even

END

SUB odd_even

INPUT "Enter a Number: ", n

IF n MOD 2 = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END SUB

Program using subroutine – Passing input as an argument

DECLARE SUB odd_even(n)

CLS

INPUT "Enter a Number: ", n

odd_even(n)

END

SUB odd_even(n)

IF n MOD 2 = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END SUB

Program using Function

DECLARE FUNCTION odd_even()

CLS

odd_even()

END

FUNCTION odd_even()

INPUT "Enter a Number: ", n

IF n MOD 2 = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END FUNCTION

Program using Function – Passing input as an argument

DECLARE FUNCTION odd_even(n AS INTEGER)

CLS

INPUT "Enter a Number: ", n

r = odd_even(n)

END

FUNCTION odd_even(n AS INTEGER)

IF n MOD 2 = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END FUNCTION

Program using Function – Passing input as an argument and returning True/False

DECLARE FUNCTION odd(n AS INTEGER)

CLS

INPUT "Enter a Number: ", n

r = odd(n)

IF r = 0 THEN

PRINT "Input Number is Even"

ELSE

PRINT "Input Number is Odd"

END IF

END

FUNCTION odd(n AS INTEGER)

odd = n MOD 2

END FUNCTION

Answered by pattu7647
1

Answer:

Output: Enter a number: 7 The given number is Odd Enter a number: 6 The given number is Even

Attachments:
Similar questions