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 matrix A [ ] [ ] of order (M x N) where ‘M’ is the number of rows
and ‘N’ is the number of columns such that both M and N must be greater than 2 and less than
10. Allow the user to input integers into this matrix. Display appropriate error message for an
invalid input.
Perform the following tasks on the matrix.
(a) Display the input matrix
(b) Create and display the mirror image matrix
(c) Calculate the sum of the four corner elements of the matrix and
display Test your program for the following data and some random data:
Example 1
INPUT: M
=3
N=
4
8 7 9 3
-2 0 4 5
1 3 6 -4
OUTPUT: ORIGINALMATRIX
8 7 9 3
-2 0 4 5
1 3 6 -4
MIRROR MATRIX
3 9 7 8
5 4 0 -2
-4 6 3 1
SUM OF THE CORNER ELEMENTS = 8
Example 2
INPUT: M=
2N
= 10
OUTPUT: INVALID INPUT
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.
Example 2
INPUT: AS YOU SOW, SO YOU REAP!
WORD TO BE INSERTED : SHALL
WORD POSITION IN THE SENTENCE :
5
OUTPUT: AS YOU SOW, SO SHALL YOU REAP!
Example 3
INPUT: BETER LATE THAN NEVER#
OUTPUT: INVALID SENTENCE
Question 4
A palindrome number is a number which when reversed is equal to the original number.
Write a program to declare a matrix A[ ][ ] of order (M X N), where ‘M’ is the number of rows and ‘N’ is
the number of columns such that ‘M’ and ‘N’ must be greater than 0 and less than 5.
Perform the following tasks on the matrix:
(a) Fill the matrix with palindrome numbers starting from 11.
Page 4 of 6
(b) Display the matrix.
(c) Find the sum of all the non border elements of the matrix.
Test run your program with the following data and some random data:
Example 1:
INPUT: M=3, N=4
OUTPUT: 11 22 33 44
55 66 77 88
99 101 111 121
Sum of Non border elements – 143
Example 2:
INPUT: M=4, N=4
OUTPUT: 11 22 33 44
55 66 77 88
99 101 111 121
131 141 151 161
Sum of Non border elements – 355
Question 5
A sentence in special form is generated by replacing each alphabet of the word with it’s next alphabet.
Write a program to input a sentence ending with a ‘.’ or ‘?’ or ‘!’. and 2 integers ‘m’ and ‘n’ (not beyond
total number of words in the sentence or less than 1). Replace each alphabet of the mth and nth word with
it’s next alphabet i.e., ‘a’ becomes ‘b’, ‘R’ becomes ‘S’ and ‘z’ becomes ‘a’. If ‘m’ and ‘n’ are equal only
one word’s alphabets are replaced.
Test your program for the following data and some random data:
Example 1:
INPUT: Sentence – There is a Buzzing sound in my ear.
m=2, n=4
OUTPUT: These jt a Cvaajooh sound in my ear.
Example 2:
INPUT: Sentence - Is it a Zebra?
m=4, n=4
OUTPUT: Is it a Afcsb?
Example 3:
INPUT: Sentence- Life is Beautiful!
m=2, n=4
Page 5 of 6
OUTPUT: Invalid Input.
Page 6 of 6