Class Practical
Class Practical
Question 1
A Composite Magic number is a positive integer which is composite as well as a magic number. Composite number: A
composite number is a number that has more than two factors. 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. Example: 28 = 2+8 = 10
= 1+0 = 1
Accept two positive integers m and n, where m is less than n as user input. Display the number of Composite Magic integers
that are in the range between m and n (both inclusive) and output them along with the frequency, in the format specified
below: Test your program for the following data and some random data.
Example 1
INPUT: m = 40
n = 100
OUTPUT: THE COMPOSITE MAGIC INTEGERS ARE:
46, 55, 64, 82, 91, 100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 6
Example 2
INPUT: m = 1210
n = 1300
OUTPUT: THE COMPOSITE MAGIC INTEGERS ARE:
1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8
Example 3
INPUT: m = 120
n = 97
OUTPUT: INVALID INPUT
Question 2
Write a program to declare a square matrix M [ ] [ ] of order ‘N’ where ‘N’ must be greater than 2 and less than 10. Accept
the value of N as user input. Display an appropriate message for an invalid input. Allow the user to accept three different
characters from the keyboard and fill the matrix according to the instruction given below:
(i) Fill the four corners of the square matrix by character 1
(ii) Fill the boundary elements of the matrix (except the four corners) by character 2
(iii) Fill the non-boundary elements of the matrix by character 3
(iv) Display the matrix formed by the above instructions
Test your program for the following data and some random data:
Example 1
INPUT: N = 3
Enter First Character: @
Enter Second Character: ?
Enter Third Character: #
OUTPUT: FORMED MATRIX
@??@
?##?
?##?
@??@
Example 2
INPUT: N = 5
Enter First Character: A
Enter Second Character: C
Enter Third Character: X
OUTPUT: FORMED MATRIX
ACCCA
CXXXC
CXXXC
CXXXC
ACCCA
Example 3
INPUT: N = 12
OUTPUT: SIZE IS OUT OF RANGE
Question 3
Write a program to accept a sentence which may be terminated by either ‘. ‘ or ?’ or ‘!’ only. Any other character may be
ignored. The words may be separated by more than one blank space and are in UPPER CASE. Perform the following tasks:
(a) Accept a sentence and remove all the extra blank space between two words to a single blank
space.
(b) Accept any word from the user along with its position and insert the word in the given position. (The position is
calculated by place value of each word where first word is in position 1, second word in position 2 and so on).
c) Display the modified sentence.
Test your program for the following data and some random data.:
Example 1
INPUT: MORNING WALK IS A BLESSING FOR THE WHOLE DAY.
WORD TO BE INSERTED: TOTAL
WORD POSITION IN THE SENTENCE: 5
OUTPUT: MORNING WALK IS A TOTAL BLESSING FOR THE WHOLE DAY.