Write a program to check whether a number entered by the user is ODD or EVEN. If the no. is ODD then find the cube of the number and if the number is EVEN then, check whether the number is a multiple of 5 or not and print appropriate message.
Answers
QUESTION:-
- Write a program to check whether a number entered by the user is ODD or EVEN. If the no. is ODD then find the cube of the number and if the number is EVEN then, check whether the number is a multiple of 5 or not and print appropriate message.
SOLUTION:-
This is done in QBASIC
___________
CODE:-
CLS
PRINT"ENTER A NUMBER"
INPUT N
IF N MOD 2=0
THEN
PRINT "EVEN NUMBER"
IF N MOD 5=0
THEN
PRINT "NUMBER IS DIVISIBLE BY 5"
ELSE PRINT "NUMBER NOT DIVISIBLE BY 5"
ENDIF
ELSE
PRINT "ODD NUMBER"
K=N*N*N
PRINT "CUBE OF THE NUMBER:"+K
ENDIF
END
_________
Variable Description:-
N--- to accept the number from the user
K--- to store the cube of the number
Required Answer:-
Question:
- Write a program to check whether a number entered by the user is ODD or EVEN. If the no. is ODD then find the cube of the number and if the number is EVEN then, check whether the number is a multiple of 5 or not and print appropriate message.
Solution:
This is written in Python.
n = int(input("Enter a number: "))
if n%2==0:
print("Number is even.")
if n%5==0:
print("Number is divisible by 5.")
else:
print("Number is not divisible by 5.")
else:
print("Number is odd.")
print("Cube of the number is",n**3)
Logic is very simple. Just input the number. Check if it's even or odd. If it's even then check if the number is divisible by 5 or not. If it's odd then display the cube of the number.
Output is attached.