All Program of Class 12 Isc
All Program of Class 12 Isc
All Program of Class 12 Isc
Write a program to declare a square matrix A[][] of order (M x 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:
(a) Sort the non-boundary elements in ascending order using
any standard sorting technique and rearrange them in the
matrix.
(b)Calculate the sum of both the diagonals.
(c) Display the original matrix, rearranged matrix and only the
diagonal elements of the rearranged matrix with their sum.
Test your program with the sample 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
Program -2
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 requiredto 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 1
INPUT: m = 100
n = 120
OUTPUT: THE UNIQUE-DIGIT INTEGERS ARE:
102, 103, 104, 105, 106, 107, 108, 109, 120
Example 2 FREQUENCY OF UNIQUE-DIGIT
INTEGERS IS: 9
INPUT: m = 2505
n = 2525
2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2519
FREQUENCY OF UNIQUE-DIGIT
INTEGERS IS: 11
Example 3
INPUT: m = 2520
n = 2529
OUTPUT: THE UNIQUE-DIGIT INTEGERS ARE: NIL
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 0.
Program 3
Write a program to accept a sentence which may be terminated by either ‘.’ ,
‘?’ or ‘!’ only. Any other character may be ignored. The words may be
separated by more than one blank space and are in UPPER CASE.
(a) Accept the sentence and reduce all the extra blank space between two
words to a single blank space.
(b) Accept a word from the user, which is a part of the sentence along with
its position number, and delete the word and display the sentence.
Test your program for the following data and some random data:
Example 1
WORD. TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6
Example 2
WORD TO BE DELETED: SO
WORD POSITION IN THE SENTENCE: 8
equivalent.
Example1
INPUT:15
BINARY EQUIVALENT: 1111
NO. OF 1’s:4
OUTPUT : EVIL NUMBER
Program -5
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. Print an error message
if the input does not terminate with ‘.’ or ‘?’. You can assume that no word in the
sentence exceeds 15 characters, so that you get a proper formatted output.
Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Program -6
Write a program to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the
number of rows and the number of columns, such that M must be greater than 2 and
less than 10. Accept the value of M as user input. Display an appropriate message
for an invalid input. Allow the user to input integers into this matrix. Perform the
following tasks:
Test your program for the following data and some random data:
Example 1
INPUT :
M=3
OUTPUT :
ORIGINAL MATRIX
Program -7
Write a Program in Java to input a word and print its anagrams..
Note: Anagrams are words made up of all the characters present in the original
word by re-arranging the characters.
Example: Anagrams of the word TOP are: TOP, TPO, OPT, OTP, PTO and POT.
Program-8
. Write a Program in Java to input a 2-D square matrix and check whether it is
an Upper Triangular Matrix or not.
Upper Triangular Matrix : An Upper Triangular matrix is a square matrix in
which all the entries below the main diagonal () are zero. The entries above or
on the main diagonal themselves may or may not be zero.
Program -9
A positive whole number 'n' that has `d' number of digits is squared and split into
two pieces, a right-hand piece that has ‘d’ digits and a left-hand piece that has
remaining ‘d’ or ‘d-1’ digits. 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
Example 1: 9
(9)2 = 81, right-hand piece of 81 = 1 and left hand piece of 81 = 8 Sum = 1 + 8 =
9, i.e. equal to the number.
Example 2: 45
(45)2 = 2025, right-hand piece of 2025 = 25 and left hand piece of 2025 = 20
Sum = 25 + 20 = 45, i.e. equal to the number.
Example 3: 297
(297)2= 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 =
88 Sum = 209 + 88 = 297, i.e. equal to the number.
Given the two positive integers p and q, where p < q, write a program to
determine how many Kaprekar numbers are there in the range between p and q
(both inclusive) and output them.
The input contains two positive integers p and q. Assume p < 5000 and q < 5000.
You are required to output the number of Kaprekar numbers 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 1
INPUT: p = 1 q = 100
OUTPUT:
(a) Find the number of words beginning and ending with a vowel.
(b) 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
Program 12-
Write a program in Java to input the first 14 digits of an IMEI
number and find the check (last) digit of it. The IMEI (15 decimal
digits: 14 digits plus a check digit) includes information on the
origin, model, and serial number of the device.
The check digit (x) is obtained by computing the sum of digits then computing 9
times that value modulo 10.
Program -13
Write a Program in Java to input a number and check whether it is a Keith
Number or not.
Note:A Keith Number is an integer N with ‘d’ digits with the following property:
If a Fibonacci-like sequence (in which each term in the sequence is the sum of the
‘d’ previous terms) is formed, with the first ‘d’ terms being the decimal digits of
the number N, then N itself occurs as a term in the sequence.
For example, 197 is a Keith number since it generates the sequence
1, 9, 7, 17, 33, 57, 107, 197, ………..
Some keith numbers are: 14 ,19, 28 , 47 , 61, 75, 197, 742, 1104, 1537……………
Program -14
A positive natural number, (for e.g. 27), can be represented as follows:
2+3+4+5+6+7
8+9+10 13+14 where every row represents a combination of
consecutive natural numbers, which add up to 27.
Write a program which inputs a positive natural number N and prints the possible
consecutive number combinations,
which when added give
Test your program for the following data and some random data.
SAMPLE DATA
INPUT: N=9
OUTPUT: 4 +5
2+3+4
Program -15
Write a program to input a string (word). Convert it into lowercase letters. Count
and print the frequency
of each alphabet present in the string. The output should be given as
Sample
Input: Alphabets OUTPUT: FREQUENCY
==========================================================
Alphabet Frequency
==========================================================
a 2
b 1
e 1
h 1
l 1
p 1
s 1
t
Program 16
- Write a Program in Java to input a number in Decimal number system and convert
it into its equivalent
number in the Hexadecimal number system.
Note: Hexadecimal Number system is a number system which can represent a
number in any other number
system in terms of digits ranging from 0 to 9 and then A – F only. This number
system consists of only sixteen
basic digits i.e. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. Here 10 is represented
as A, 11 as B and so on
till 15 which is represented as F.
For Example: 47 in the Decimal number system can be represented as 2F in the
Hexadecimal number system.
Program -17
A number is said to be an Ugly number if positive numbers whose prime factors
only include 2, 3, 5
For example, 6(2×3), 8(2x2x2), 15(3×5) are ugly numbers while 14(2×7) is not
ugly since it includes another prime factor 7. Note that 1 is typically treated as an
ugly number.
Program 18
Write a Program in Java to fill a 2-D array with the first ‘m*n’ prime numbers,
where ‘m’ is the number of rows and ‘n’ is the number of columns.
Program 19-
Write a program to print the words of the input in reverse order without any
punctuation marks other than blanks.
For example, Consider the following input text:
INPUT:
Enter number of sentences: 2
Enter the sentences:
This is a sample piece of text to illustrate this question
if you are smart you will solve this right.
OUTPUT: right this solve will you smart are you if question this illustrate to text
of piece sample a is this
NOTE : Individual words (i.e. characters of every word) are not reversed
Test your program for the following data and some random data:
Sample Input 1 :
Enter number of sentences: 1
Enter the text:
Do not judge a book by its cover.
Sample Output: Cover its by book a judge not do
Program -20
A Goldbach number is positive even integer that can be expressed as the sum of two
odd pimes (All even integer numbers greater than 4 are Goldbach number.
Eg: 6=3+3
10=3+7
10=5+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.
Program 21
Prime number: A number which has only two factors, i.e. 1 and the number
itself.
(13)2 = 169
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
Program 22
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:
Example 1:
INPUT:
M=1
N=3
ENTER ELEMENTS FOR ROW 1: 1 4 4
OUTPUT:
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:
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
Program 23-
Design a program to accept a day number (between 1 and 366), year (in 4 digits)
from the user to generate and display the corresponding date. Also, accept 'N' (1
<= N <= 100) from the user to compute and display the future date corresponding
to 'N' days after the generated date. Display an error message if the value of the
day number, year and N are not within the limit or not according to the condition
specified.
Test your program with the following data and some random data:
Example 1
INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT:
DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018
Example 2
INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45
OUTPUT:
DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019
Example 3
INPUT:
DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33
OUTPUT:
DAY NUMBER OUT OF RANGE
Example 4
INPUT:
DAY NUMBER: 150
YEAR: 2018
DATE AFTER (N DAYS): 330
OUTPUT:
DATE AFTER (N DAYS) OUT OF RANGE
Program 24.
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
uppercase.
(b) Convert the non-palindrome words of the sentence into palindrome words by
concatenating the word by its reverse (excluding the last character).
Example:
The reverse of the word HELP would be LEH (omitting the last alphabet) and by
concatenating both, the new palindrome word is HELPLEH. Thus, the word
HELP becomes HELPLEH.
Note: The words which end with repeated alphabets, for example ABB would
become ABBA and not ABBBA and XAZZZ becomes XAZZZAX.
[Palindrome word: Spells same from either side. Example: DAD, MADAM etc.]
(c) Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:
Example 1
INPUT:
THE BIRD IS FLYING.
OUTPUT:
THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYINGNIYLF
Example 2
INPUT:
IS THE WATER LEVEL RISING?
OUTPUT:
IS THE WATER LEVEL RISING?
ISI THEHT WATERETAW LEVEL RISINGNISIR
Example 3
INPUT:
THIS MOBILE APP LOOKS FINE.
OUTPUT:
THIS MOBILE APP LOOKS FINE.
THISIHT MOBILELIBOM APPA LOOKSKOOL FINENIF
Example 3
INPUT:
YOU MUST BE CRAZY#
OUTPUT:
INVALID INPUT
Program 25-
Test your program for the following data and some random data:
Example 1
INPUT:
N=3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote
OUTPUT:
E R C
m o o
u a y
s d o
t
R e
o
l
s
Example 2
INPUT:
N=4
Team 1: Royal
Team 2: Mars
Team 3: De Rose
Team 4: Kings
OUTPUT:
R M D K
o a e i
y r n
a s R g
l o s
s
e
Example 3
INPUT:
N = 10
OUTPUT:
INVALID INPUT
Program 26-
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
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
Program 27
A/a B/b C/c D/d E/e F/f G/g H/h I/i J/j K/k L/l M/m
↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕
N/n O/o P/p Q/q R/r S/s T/t U/u V/v W/w X/x Y/y Z/z
Write a program to accept a plain text of length L, where L must be greater than 3
and less than 100.
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
Program 28
Program 29
A linear data structure enables the user to add an address from rear end and remove
address from front. Define a class Diary with the following details :
Class name: Diary
Data members/instance variables:
Q[]: array to store the addresses
size: stores the maximum capacity of the array
start: to point the index of the front end
end: to point the index of the rear end
Member functions:
Diary(int max): constructor to initialize the data member size = max, start=0 and
end=0
void pushadd(String n): to add the address in the diary from the rear end if possible,
otherwise display the message “NO SPACE”
String popadd(): removes and returns the address from the front end of the diary if
any, else returns “?????”
void show (): displays all the addresses in the diary
Specify the class Diary giving details of the functions void pushadd(String) and
String popadd(). Assume that the other functions have been defined.
Program 30
A register is an entity which can hold a maximum of 100 names. The register enables
the user to add and remove names from the topmost end only.
Define a class Register with the following details:
Class name: Register
Data members/instance variables:
stud[]: array to store the names of the students
cap: stores the maximum capacity of the array to point the index of the top end
top: to point the index of the top end
Member functions:
Register (int max) : constructor to initialize the data member cap = max, top = -1 and
create the string array
void push(String n): to add names in the register at the top location if possible,
otherwise display the message “OVERFLOW” String pop(): removes and returns the
names from the topmost location of the register if any, else returns “$$”
void display (): displays all the names in the register
Specify the class Register giving details of the functions void push(String) and String
pop().
Assume that the other functions have been defined.