CLASS 12
COMPUTER SCIENCE
Solve All Programs
Question 1
A Vampire number is a composite natural number with an even number of digits that
can be factored into two natural numbers each with half as many digits as the original
number and not both with trailing zeros, where the two factors contain precisely all the
digits of the original number, in any order of counting multiplicity.
Example: 1260 = 21 x 60 ( where, 21 and 60 contain precisely all the digits of the
number )
Thus, 1260 is a Vampire number.
Accept two positive integers m and n, where m is less than n and the values of both ‘m’
and ‘n’ must be greater than or equal to 1000 and less than or equal to 9999 as user
input. Display all Vampire numbers 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 = 1002
n = 1640
OUTPUT: THE VAMPIRE NUMBERS ARE:
1260 1395 1435 1530
FREQUENCY OF VAMPIRE NUMBER IS: 4
Example 2
INPUT: m = 1810
n = 7800
OUTPUT: THE VAMPIRE NUMBERS ARE:
1827 2187 6880
FREQUENCY OF VAMPIRE NUMBER IS: 3
Example 3
INPUT: m = 8105
n = 9999
OUTPUT: THE VAMPIRE NUMBERS ARE:
NIL
FREQUENCY OF VAMPIRE NUMBER IS: 0
Example 4
INPUT: m = 174
n = 4500
OUTPUT: INVALID INPU
Question 2
Hamming numbers are positive integer numbers whose prime factors include 2,3 and 5
only
Example:
n=6 is an hamming number as 6=2x3 .So its prime factors are limited to 2 ,3
n=8 is an hamming number as 8=2x2x2 and it has only 2 as its prime factors
n=90 is an hamming number as 90=2x3x3x5 which has only 2,3,5 as prime factors
n=14 is not a hamming number as 14=2x7 .It has 7 as one of its prime factor
n=44 is not a hamming number as 44=2x2x11. It has 11 as one of its prime factors
Design a program to accept any positive integer number and check if it is a Hamming
number or not. Display the result with an appropriate message in the format specified
below. The program should also generate error message if a negative number is
entered.
Test your program for the following data and some random data.
Example 1
INPUT: Enter any number: 3600
OUTPUT: 3600= 2 x 2 x 2 x 2 x 3 x 3 x 5 x 5
3600 IS A HAMMING NUMBER
Example 2
INPUT: Enter any number: 5832
OUTPUT: 5832= 2 x 2 x 2 x 3 x 3 x 3 x 3 x 3 x 3
5832 IS A HAMMING NUMBER
Example 3
INPUT: Enter any number: 7854
OUTPUT: 7854= 2 x 3 x 7 x 11 x 17
7854 IS NOT A HAMMING NUMBER
Example 4
INPUT: Enter a number: -120
OUTPUT: NEGATIVE NUMBER ENTERED. INVALID INPUT
Question 3
A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as
well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself.
Example: 2, 3, 5, 7 ... etc.
Adam number: The square of a number and the square of its reverse are reverse to each
other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169
thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all
Prime-Adam integers that are in the range between m and n (both inclusive) and output
them along with the frequency, in the format given below:
Test your program with the following data and some random data:
Example 1
INPUT: m=5
n = 100
OUTPUT: THE PRIME-ADAM INTEGERS ARE:
11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2
INPUT: m = 100
n = 200
OUTPUT: THE PRIME-ADAM INTEGERS ARE:
101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT: m = 50
n = 70
OUTPUT: THE PRIME-ADAM INTEGERS ARE:
NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS: 0
Example 4
INPUT: m = 700
n = 450
OUTPUT: INVALID INPUT
Question 4
A Goldbach number is a positive even integer that can be expressed as the sum of
two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3
and 7, 5 and 5.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the
odd prime pairs whose sum is equal to the number 'N'.
Test your program with the following data and some random data:
Example 1
INPUT:
N = 14
OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2
INPUT:
N = 30
OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17
Example 3
INPUT:
N = 17
OUTPUT:
INVALID INPUT. NUMBER IS ODD.
Example 4
INPUT:
N = 126
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.
Question 5
A snowball string is a sentence where each word is arranged in ascending order of their
length and is also consecutive.
For example “I am the Lord” is a snowball string as
Length of word ‘I’ is 1
Length of word ‘am’ is 2
Length of word ‘the’ is 3
Length of word ‘Lord’ is 4
The length of each word is one more than the previous word. Hence they are
consecutive and in ascending order.
Write a program to enter any sentence and check if it is a snowball string or not. The
words in the sentence may be separated by a one or more spaces and terminated by ‘.’
or ‘?’ only. The program will generate appropriate error message for any other
terminating character.
Test your program for the following data and some random data:
Example 1
INPUT: He may give bonus.
OUTPUT: IT IS A SNOWBALL STRING
Example 2
INPUT: Is the cold water frozen?
OUTPUT: IT IS A SNOWBALL STRING
Example 3
INPUT: Look before you leap.
OUTPUT: IT IS NOT A SNOWBALL STRING
Example 4
INPUT: The child is father of the man!
OUTPUT: INCORRECT TERMINATING CHARACTER. INVALID INPUT
Question 6
Write a program to accept a sentence which may be terminated by either ‘.’ , ‘?’ or ‘!’
only. The words may be separated by a single blank space and are in UPPER CASE.
Perform the following tasks:
(a) Count number of vowels and consonants present in each word
(b) Generate the output of the frequency in form of a bar graph, where V denotes
vowels and C consonants as shown below:
Test your program for the following data and some random data:
Example 1
INPUT: HOW ARE YOU?
OUTPUT: WORD COUNT
HOW V
CC
ARE VV
C
YOU VV
C
Example 2
INPUT: GOOD DAY!
OUTPUT: WORD COUNT
GOOD VV
CC
DAY V
CC
Example 3
INPUT: LONG LIVE THE KING#
OUTPUT: INCORRECT TERMINATING CHARACTER.
INVALID INPUT
Question 7
Write a program to accept a sentence which may be terminated by either '.', '?' or '!'
only. The words are to be separated by a single blank space and are in UPPER CASE.
Perform the following tasks:
Check for the validity of the accepted sentence only for the terminating character.
Arrange the words in ascending order of their length. If two or more words have the
same length, then sort them alphabetically.
Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:
Example 1:
INPUT: AS YOU SOW SO SHALL YOU REAP.
OUTPUT: AS YOU SOW SO SHALL YOU REAP.
AS SO SOW YOU YOU REAP SHALL
Example 2:
INPUT: SELF HELP IS THE BEST HELP.
OUTPUT: SELF HELP IS THE BEST HELP.
IS THE BEST HELP HELP SELF
Example 3:
INPUT: BE KIND TO OTHERS.
OUTPUT: BE KIND TO OTHERS.
BE TO KIND OTHERS
Example 4:
INPUT: NOTHING IS IMPOSSIBLE#
OUTPUT: INVALID INPUT
Question 8
Caesar Cipher is an encryption technique which is implemented as ROT13 ('rotate by
13 places'). It is a simple letter substitution cipher that replaces a letter with the letter
13 places after it in the alphabets, with the other characters remaining unchanged.
ROT13
A/ B/ C/ D/ E/ F/ G/ H/ K/ M/
I/i J/j L/l
a b c d e f g h k m
↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕
N/ O/ P/ Q/ R/ S/ U/ V/ W/ X/ Y/
T/t Z/z
n o p q r s u v w x y
Write a program to accept a plain text of length L, where L must be greater than 3
and less than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data.
Example 1
INPUT:
Hello! How are you?
OUTPUT:
The cipher text is:
Uryyb! Ubj ner lbh?
Example 2
INPUT:
Encryption helps to secure data.
OUTPUT:
The cipher text is:
Rapelcgvba urycf gb frpher qngn.
Example 3
INPUT:
You
OUTPUT:
INVALID LENGTH
Question 9
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 the value of 'M' must be greater
than 0 and less than 10 and the value of 'N' must be greater than 2 and less than 6.
Allow the user to input digits (0 - 7) only at each location, such that each row
represents an octal number.
Example:
2 3 1 (decimal equivalent of 1 st row = 153 i.e. 2x82 + 3x81 + 1x80)
4 0 5 (decimal equivalent of 2 nd row = 261 i.e. 4x82 + 0x81 + 5x80)
1 5 6 (decimal equivalent of 3 rd row = 110 i.e. 1x82 + 5x81 + 6x80)
Perform the following tasks on the matrix:
1. Display the original matrix.
2. Calculate the decimal equivalent for each row and display as per the format
given below.
Test your program for the following data and some random data:
Example 1:
INPUT:
M=1
N=3
ENTER ELEMENTS FOR ROW 1: 1 4 4
OUTPUT:
FILLED MATRIX DECIMAL EQUIVALENT
1 4 4 100
Example 2:
INPUT:
M=3
N=4
ENTER ELEMENTS FOR ROW 1: 1 1 3 7
ENTER ELEMENTS FOR ROW 2: 2 1 0 6
ENTER ELEMENTS FOR ROW 3: 0 2 4 5
OUTPUT:
FILLED DECIMAL
MATRIX EQUIVALENT
1 1 3 7 607
2 1 0 6 1094
0 2 4 5 165
Example 3:
INPUT:
M=3
N=3
ENTER ELEMENTS FOR ROW 1: 2 4 8
OUTPUT:
INVALID INPUT
Example 4:
INPUT:
M=4
N=6
OUTPUT:
OUT OF RANGE
Question 10
Write a program to declare a square matrix M[][] of order ‘N’. Check if the matrix is a
Doubly Markov matrix or not. A matrix which satisfies the following conditions are
Doubly Markov matrix
(i) All elements are greater than or equal to 0
(ii) Sum of each row is equal to 1.
(iii) Sum of each column is equal to 1.
Accept ‘N’ from the user where 3 <= N <= 9. Display an appropriate error message if
‘N’ is not in the given range or the entered numbers are negative. Allow the user to
create a matrix and check whether the created matrix is a Doubly Markov matrix or not
Test your program for the following data and some random data:
Example 1
INPUT: N=3
Enter elements in the matrix: 0.5, 0.25, 0.25, 0.25, 0.75, 0.0, 0.25, 0.0, 0.75
OUTPUT: FORMED MATRIX
0.5 0.25 0.25
0.25 0.75 0.0
0.25 0.0 0.75
IT IS A DOUBLY MARKOV MATRIX
Example 2
INPUT: N=3
Enter elements in the matrix: 1.5, 3, 0.15, 0.25, 4, 1.0, 0.25, 1.0, 3
OUTPUT: FORMED MATRIX
1.5 3 0.15
0.25 4 1.0
0.25 1.0 3
IT IS NOT A DOUBLY MARKOV MATRIX
Example 3
INPUT: N=2
Enter elements in the matrix: 0.8, -4.0, 0.9, 3.5
OUTPUT: NEGATIVE NUMBERS ENTERED. INVALID ENTRY
Example 4
INPUT: N =12
OUTPUT: SIZE IS OUT OF RANGE. INVALID ENTRY
Question 11
Write a program to declare a matrix a[][] of order (m × n) where 'm' is the number of
rows and 'n' is the number of columns such that the values of both 'm' and 'n' must be
greater than 2 and less than 10. Allow the user to input integers into this matrix.
Perform the following tasks on the matrix:
1. Display the original matrix.
2. Sort each row of the matrix in ascending order using any standard sorting
technique.
3. Display the changed matrix after sorting each row.
Test your program for the following data and some random data:
Example 1
INPUT:
M=4
N=3
ENTER ELEMENTS OF MATRIX:
11 −2 3
5 16 7
9 0 4
3 1 8
OUTPUT:
ORIGINAL MATRIX
11 −2 3
5 16 7
9 0 4
3 1 8
MATRIX AFTER SORTING ROWS
−2 3 11
5 7 16
0 4 9
1 3 8
Example 2
INPUT:
M=3
N=3
ENTER ELEMENTS OF MATRIX
22 5 19
7 36 12
9 13 6
OUTPUT:
ORIGINAL MATRIX
22 5 19
7 36 12
9 13 6
MATRIX AFTER SORTING ROWS
5 19 22
7 12 36
6 9 13
Example 3
INPUT:
M = 11
N=5
OUTPUT:
MATRIX SIZE OUT OF RANGE.
Question 12
Write a program to declare a square matrix A[][] of order (M × M) where 'M' must be
greater than 3 and less than 10. Allow the user to input positive integers into this
matrix. Perform the following tasks on the matrix:
1. Sort the non-boundary elements in ascending order using any standard sorting
technique and rearrange them in the matrix.
2. Calculate the sum of both the diagonals.
3. Display the original matrix, rearranged matrix and only the diagonal elements
of the rearranged matrix with their sum.
Test your program for the following data and some random data:
Example 1
INPUT:
M=4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8
SUM OF THE DIAGONAL ELEMENTS = 59
Example 2
INPUT:
M=5
7 4 1 9 5
8 2 6 10 19
13 1 3 5 1
10 0 5 12 16
1 8 17 6 8
OUTPUT:
ORIGINAL MATRIX
7 4 1 9 5
8 2 6 10 19
13 1 3 5 1
10 0 5 12 16
1 8 17 6 8
REARRANGED MATRIX
7 4 1 9 5
8 0 1 2 19
13 3 5 5 1
10 6 10 12 16
1 8 17 6 8
DIAGONAL ELEMENTS
7 5
0 2
5
6 12
1 8
SUM OF THE DIAGONAL ELEMENTS = 46
Example 3
INPUT:
M=3
OUTPUT:
THE MATRIX SIZE IS OUT OF RANGE.
Question 13
A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the
leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number
is still prime. The process is repeated until the original number is reached again.
A number is said to be prime if it has only two factors 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Accept a positive number N and check whether it is a circular prime or not. The new numbers formed
after the shifting of the digits should also be displayed.
Test your program with the following data and some random data:
Example 1 INPUT:
N = 197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME.
Question 14
Write a program to declare a square matrix A[][] of order (M × M) where 'M' must be greater than 3
and less than 10. Allow the user to input positive integers into this matrix. Perform the following tasks
on the matrix:
Sort the non-boundary elements in ascending order using any standard sorting technique and rearrange
them in the matrix.
Calculate the sum of both the diagonals.
Display the original matrix, rearranged matrix and only the diagonal elements of the rearranged matrix
with their sum.
Test your program for the following data and some random data:
Example 1 INPUT:
M=4
92 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
92 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
92 1 5
83 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8
SUM OF THE DIAGONAL ELEMENTS = 59
Question 15
Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The words
may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
Find the number of words beginning and ending with a vowel.
Place the words which begin and end with a vowel at the beginning, followed by the remaining words
as they occur in the sentence.
Test your program with the sample data and some random data:
Example 1 INPUT:
ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 3 ANAMIKA ARE
ANYMORE AND SUSAN NEVER GOING TO QUARREL
Question 16
A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes, 12 boxes,
24 boxes and 48 boxes. Design a program to accept the number of boxes to be packed (N) by the user
(maximum up to 1000 boxes) and display the break-up of the cartons used in descending order of
capacity (i.e. preference should be given to the highest capacity available, and if boxes left are less than
6, an extra carton of capacity 6 should be used.)
Test your program with the following data and some random data:
Example 1 INPUT:
N = 726
OUTPUT:
48 * 15 = 720
6*1=6
Remaining boxes = 0
Total number of boxes = 726 Total number of cartons = 16
Page 17 of 26
Example 2 INPUT:
N = 140
OUTPUT:
48 * 2 = 96
24 * 1 = 24
12 * 1 = 12
6*1=6
Remaining boxes = 2 * 1 = 2 Total number of boxes = 140 Total number of cartons = 6
Example 3 INPUT:
N = 4296
OUTPUT:
INVALID INPUT
Question 17
A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well as an
Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself. Example: 2, 3, 5,
7 ... etc.
Adam number: The square of a number and the square of its reverse are reverse to each other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169 thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all Prime-Adam
integers that are in the range between m and n (both inclusive) and output them along with the
frequency, in the format given below:
Test your program with the following data and some random data:
Question 18
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 the value of 'M' must be greater than 0 and less than 10 and the value
of 'N' must be greater than 2 and less than 6. Allow the user to input digits (0 - 7) only at each location,
such that each row represents an octal number.
Example:
2 3 1 (decimal equivalent of 1st row = 153 i.e. 2x82 + 3x81 + 1x80)
4 0 5 (decimal equivalent of 2nd row = 261 i.e. 4x82 + 0x81 + 5x80)
1 5 6 (decimal equivalent of 3rd row = 110 i.e. 1x82 + 5x81 + 6x80)
Perform the following tasks on the matrix:
Display the original matrix.
Calculate the decimal equivalent for each row and display as per the format given below. Test your
program for the following data and some random data:
Page 18 of 26
Example 1:
INPUT:
M=1
N=3
ENTER ELEMENTS FOR ROW 1: 1 4 4
OUTPUT:
FILLED MATRIX DECIMAL EQUIVALENT
1 4 4 100
Example 2:
INPUT:
M=3
N=4
ENTER ELEMENTS FOR ROW 1: 1 1 3 7
ENTER ELEMENTS FOR ROW 2: 2 1 0 6
ENTER ELEMENTS FOR ROW 3: 0 2 4 5
OUTPUT:
FILLED MATRIX DECIMAL EQUIVALENT
1 1 3 7 607
2 1 0 6 1094
0 2 4 5 165
Example 3:
INPUT:
M=3
N=3
ENTER ELEMENTS FOR ROW 1: 2 4 8
OUTPUT:
Page 19 of 26
INVALID INPUT
Example 4:
INPUT:
M=4
N=6
OUTPUT:
OUT OF RANGE
Question 19
A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the odd prime pairs
whose sum is equal to the number 'N'.
Test your program with the following data and some random data:
Example 1
INPUT:
N = 14
OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2 INPUT:
N = 30
OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17
Page 20 of 26
Example 3 INPUT:
N = 17
OUTPUT:
INVALID INPUT. NUMBER IS ODD.
Example 4 INPUT:
N = 126
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.
Question 20
Write a program to declare a matrix a[][] of order (m × n) where 'm' is the number of rows and 'n' is
the number of columns such that the values of both 'm' and 'n' must be greater than 2 and less than
10. Allow the user to input integers into this matrix. Perform the following tasks on the matrix:
Display the original matrix.
Sort each row of the matrix in ascending order using any standard sorting technique. Display the
changed matrix after sorting each row.
Test your program for the following data and some random data:
Example 1
INPUT:
M=4
N=3
ENTER ELEMENTS OF MATRIX:
11 -2 3
5 16 7
9 0 4
3 1 8
OUTPUT:
ORIGINAL MATRIX
11 -2 3
5 16 7
9 0 4
3 1 8
MATRIX AFTER SORTING ROWS
Page 21 of 26
-2 3 11
5 7 16
0 4 9
1 3 8
Example 2:
M = 11
N=5
OUTPUT:
MATRIX SIZE OUT OF RANGE.
Question 21
Write a program to declare a single-dimensional array a[] and a square matrix b[][] of size N, where
N
> 2 and N < 10. Allow the user to input positive integers into the single dimensional array. Perform
the following tasks on the matrix:
Sort the elements of the single-dimensional array in ascending order using any standard sorting
technique and display the sorted elements.
Fill the square matrix b[][] in the following format:
If the array a[] = {5, 2, 8, 1} then, after sorting a[] = {1, 2, 5, 8} Then, the matrix b[][] would fill as
below:
1258
1251
1212
1125
Question 22
Page 22 of 26
Question 1
A unique-digit integer is a positive integer (without leading zeros) with no duplicate digits. For example,
7, 135, 214 are all unique-digit integers whereas 33, 3121, 300 are not.
Given two positive integers m and n, where m < n, write a program to determine how many unique-
digit integers are there in the range between m and n (both inclusive) and output them.
The input contains two positive integers m and n. Assume m < 30000 and n < 30000. You are to output
the number of unique-digit integers in the specified range along with their values in the format specified
below:
Test your program for the following data and some random data.
Example 23
INPUT: m = 100 n = 120
OUTPUT: THE UNIQUE-DIGIT INTEGERS ARE:
102, 103, 104, 105, 106, 107, 108, 109, 120
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 9
Example 2
INPUT: m = 2505 n = 2525
OUTPUT: THE UNIQUE-DIGIT INTEGERS ARE:
2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2519
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 11
Page 23 of 26
Example 3
INPUT: m = 2520 n = 2529
OUTPUT: THE UNIQUE-DIGIT INTEGERS ARE: NIL
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 0.
Question 24
Write a program to declare a matrix A [ ] [ ] of order (M × 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 than10, also
M and N values are same. 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) Rotate the matrix by 1800 degrees and display the resultant matrix
(c) Calculate the sum of the left and right diagonal elements of the matrix and display
Test your program for the following data and some random data:
Example 1
INPUT: M=3
N=3
ENTER ELEMENTS: 1, 2, 3, 4, 5, 6, 7, 8, 9
OUTPUT: ORIGINALMATRIX
1 2 3
4 5 6
7 8 9
ROTATED MATRIX BY 180 DEGREE
9 8 7
6 5 4
3 2 1
SUM OF THE LEFT AND RIGHT DIAGONAL ELEMENTS = 25
Example 2
INPUT: M=4
N=4
ENTER ELEMENTS: 7, 9, -5, 8, 2, -4, 18, 6, 5,12, 36, 9, 8, -7, 89, 1
OUTPUT: ORIGINALMATRIX
7 9 -5 8
2 -4 18 6
5 12 36 9
8 -7 89 1
ROTATED MATRIX BY 180 DEGREE
1 89 -7 8
9 36 12 5
6 18 -4 2
8 -5 9 7
SUM OF THE LEFT AND RIGHT DIAGONAL ELEMENTS = 86
Example 3
Page 24 of 26
INPUT: M=2
N = 10
OUTPUT: INVALID INPUT. OUT OF RANGE.
Example 4
INPUT: M=6
N=4
OUTPUT: INVALID INPUT. VALUE OF M AND N NOT SAME
Question 25
Write a program to accept a sentence which may be terminated by either ‘.’ ,‘?’or ‘!’ only. The words
may be separated by a single blank space and should be case-insensitive.
Perform the following tasks:
(a) Determine if the accepted sentence is a Pangram or not.
[A Pangram is a sentence that contains every letter of the alphabet at least once.] Example: "The quick
brown fox jumps over the lazy dog"
(b) Display the first occurring longest and shortest word in the accepted sentence.
Test your program for the following data and some random data:
Example 1
INPUT: Pack my box with five dozen liquor jugs.
OUTPUT: IT IS A PANGRAM
LONGEST WORD: dozen SHORTEST WORD: my
Example 2
INPUT: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
OUTPUT: IT IS A PANGRAM
LONGEST WORD: QUICK SHORTEST WORD: THE
Example 3
INPUT: Hello my World.
OUTPUT: IT IS NOT A PANGRAM
LONGEST WORD: Hello SHORTEST WORD: my
Example 4
INPUT: Alas ! it failed #
OUTPUT: INVALID INPUT
Note for Assignment:
Page 25 of 26
1. Front Page (no page no)
2. Contents (no page no)
3. Algorithm
4. Coding
5. Output
6. Variable Description
7. Teacher Signature (no page no)
Page 26 of 26