Page 270 - Computer science 868 Class 12
P. 270
2. A Composite Magic number is a positive integer that is a composite as well as a magic number.
Composite number:
A composite number is a number that has more than two factors.
For example: 10
Factors are: 1, 2, 5, 10
Magic number:
A magic number is a number in which the eventual sum of the digits is equal to 1.
For example: 28=2+8 = 10=1+0 = 1
Class name : calculate
Data Members : int n
Member Methods
void input() : Inputs a number
boolean composite() : returns true if composite else returns false
boolean magic() : returns true if magic number else returns false
void check() : calls composite() and magic() and prints whether it is a
a. magic number
b. composite number
c. Composite Magic number
3. Consider the sequence of natural numbers.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 …………………
Removing every second number produces the sequence as
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 …………………
Removing every third number produces the sequence as
1, 3, 7, 9, 13, 15, 19, 21, 25 …………………
This process continues indefinitely by removing the fourth, fifth…and so on, till after a fixed number of steps, certain natural
numbers remain indefinitely. These are known as Lucky Numbers.
Write a program to generate and print lucky numbers less than a given number N.
SAMPLE INPUT : N = 10
OUTPUT : The Lucky numbers less than 10 are: 1 3 7
SAMPLE INPUT : N = 25
OUTPUT : The Lucky numbers less than 25 are: 1 3 7 13 19
class : lucky
Data Members : int n
Member Methods
void input() : Inputs n
void generate() : Prints the lucky numbers less than n
4. A Kaprekar number is a number whose square is divided into two parts in such a manner that sum of the parts is equal to the
original number and none of the parts has a value 0.
If the sum of the two pieces is equal to the number, then ‘n’ is a Kaprekar number.
The first few Kaprekar numbers are: 9, 45, 297 ………………….
class : Kaprekar
Data Members : int n
Member Methods
Kaprekar() : constructor to assign 0 to n
void input() : inputs n
boolean generate_kaprekar() : returns true if n is kaprekar number else returns false
void display() : prints the number is a Kaprekar number or not by invoking generate_kaprekar() method
5. Design a class Perfect to check if a given number is a perfect number or not. A number is said to be perfect if the sum of the factors
of the number excluding itself is equal to the original number.
Example: 6 = 1 + 2 + 3 (where 1, 2 and 3 are factors of 6, excluding itself)
Some of the members of the class are given below.
Class name : Perfect
Data Members/Instance variables
num : to store the number
268268 Touchpad Computer Science-XII

