Page 374 - Computer Science Class 11 Without Functions
P. 374
Program 6
Write a program that takes a number as an input and checks whether it is an armstrong number or not. The
Armstrong number is a number that is equal to the sum of the cubes of its digits. For example, 0, 1, 153, 370, 371,
and 407 are the Armstrong numbers.
Ans. '''
Objective: To check whether a number is an armstrong number
Input: num
Output: result whether it is armstrong number or not
'''
num = int(input("Enter a Number: "))
n = num #storing the number for later usage
sumCubeDigits = 0
while n > 0:
sumCubeDigits += (n % 10) * (n % 10) * (n % 10)
n //= 10
if num == sumCubeDigits:
print(num,"is an Armstrong number.")
else:
print(num,"is not an Armstrong number.")
Program 7
Write a program that takes a number as an input and checks whether it is a palindrome or not. A palindromic
number (also known as a numeral palindrome or a numeric palindrome) is a number (such as 16461) that remains
the same when its digits are reversed.
Ans. '''
Objective: To check whether a number is a palindrome
Input: num
Output: result whether it is a palindrome or not
'''
num = int(input("Enter a Number: "))
n = num #storing the number for later usage
reverseNum = 0
remainder = 0
while num > 0:
remainder = num %10
reverseNum = reverseNum * 10 + remainder
num //= 10
if n == reverseNum:
print("Given number is a palindrome")
372 Touchpad Computer Science-XI

