Page 506 - ComputerScience_Class_11
P. 506
Output
Enter your choice: 2
1 2 3 4
2 3 4
3 4
4
Program 6: Write a program to enter any number and check if it is an Armstrong number or not. An Armstrong number
is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example,
153 is an Armstrong number because (13 + 53 + 33 = 153).
Program 6.py
File Edit Format Run Options Window Help
import math
n=int(input('Enter a number: '))
c=n
s=0
l=int(math.log10(n))+1
while c>0:
d=c%10
s=s+d**l
c=c//10
if s==n:
print(n,'is an Armstrong number')
else:
print(n,'is not an Armstrong number')
Output
Enter a number: 370
370 is an Armstrong number
Program 7: Write a program in java to accept a number and check if it is a Bouncy number or not. A number is said to
Bouncy number if it is greater than 100 and if the digits of the number are not in sorted order.
Example: 12345: It is not a Bouncy number because the digits are sorted in ascending order.
98764: It is not a Bouncy number because the digits are sorted in descending order.
15296: It is a Bouncy number because the digits are unsorted.
504 Touchpad Computer Science (Ver. 3.0)-XI

