Practical Questions Class XII
Practical Questions Class XII
Practical Questions Class XII
1. Prime numbers: Num. Have only two factors 2, 3, 5, 7, 11, 13, 17, 19 .....
A. Input a number and print the nearest prime number greater than the number. Example: for
8 output is 11, for 13 output is 17
A. Input two prime numbers and check if they are successive prime numbers. Example: 11 and
13, 17 and 19, 5 and 7
A. Primorial number: Product of first N prime numbers is the primorial of that number.
Primorial of 3 is (2*3*5) 30. Primorial of 5 is (2*3*5*7*11) 2310
2. Twin Prime Numbers: Pair of prime nums. with a diff of 2 (3,5) (5,7) (11,13) (17,19)...
3. Prime Circular nos.: All permutations of prime num. are also prime (13, 31) (113, 131, 311)
(All the possible numbers formed by shifting digits in circular manner are prime.)
5. Prime Factors: Factors of number that are prime: Prime factors of 12 are 2 and 3
7. Palindrome number: Read same left to right and right to left. 11, 121, 303, 4114...
B. Input a number and check if it is palindrome. If not then obtain the palindrome by joining
the number with its reverse. Example: 369 become 369963
9. Emrip Numbers: Reverse of a prime num is also prime: (13, 31) (17, 71) (113, 311)
10. Smith number: (666) sum of digits = sum of its Prime Factorizations
11. Perfect num. : Sum of factors <than the number = to the number (6, 28....)
B. Abundant number: If the sum of the factors is greater than twice the number. Example:12
Sum of factors of 12=(1+2+3+4+6+12) 28 which is greater than (2*12) 24
C. Deficient Number: If the sum of the factors is smaller than twice the number. Example:16
Sum of factors of 16=(1+2+4+8+16) 31 which is smaller than (2*16) 32
D. Subline Number: Sum of factor and count of factors both are perfect numbers. Example:12
Factors of 12 are: 1,2,3,4,6 and 12. There are 6 factors. Sum of these factors is 28. Both 6
and 28 are perfect numbers.
D. Equivalent Number: Sum of the factors (not including number itself) for any two given
number is same: Example: 159 and 703 sum of factors for both is 57, 12 and 26 sum of
factors for both is 16 .
1
12. Amicable num.: X = sum of factors – num itself. Y = sum of factors of X <X . Y = N. (Num =
220. X = sum of factors of N < N. X = 284. Y = 220 which is sum of factors of X < X. Y = N)
13. Armstrong number: 153 : sum of cubes of each digit = number. (1+125+27)=153
14. Super Palindrome number: Square of a palindrome num is also palindrome. 11 is SP as its
square 121 is also palindrome.
15. Special number: 145: Sum of the Factorial of each digit is = number. (1+24+120)= 145
D. Input a number and print the binary equivalent of the number. Binary of 9 is 1001,
14 is 1110 , 26 is 11010
D. Input a number and print he binary equivalent of the number in 8 bits. Binary of 9 in eight
bits is 00001001, Binary of 14 in eight bits is 00001110, binary of 26 in eight bits is 00011010
D. Two digit special number: A special two-digit number is a number such that when the sum of
the digits of the number is added to the product of its digits, the result is equal to the
original two-digit number. Example 59. Sum of digits (5+9)=14 + product of digits (5*9)45 is
(14+45) = 59
16. Automorphic/ circular num: Num. is present to the extreme right of its square (5, 6, 25, 625)
17. Super Automorphic num.: Square of Automorphic num is also Automorphic. 25 is SA as its
square 625 is also Automorphic. 5 is super Automorphic as its square 25 is also Automorphic.
18. Magic number : Final Sum of digits comes to 1. (9991 = (9+9+9+1) 28 = (2+8) 10 = (1+0) =1)
19. Happy number: Final sum of the square of digits comes to 1. (7 ( 7*7) = 49 (4*4 + 9*9) = 97
(9*9 + 7*7) = 130 (1*1 + 3*3 + 0*0) = 10 (1*1 + 0*0) = 1
20. Mobious: Count of prime factorization (CF) Function returns 1 if CF is even or if num is 1.
Function returns -1 if CF is odd. Function returns 0 if any prime factorisation is repeated.
21. Fibonacci series: 0 , 1 , 1, 2, 3, 5, 8, 13... third term is the sum of previous two terms.
22. Locus series: 3, 7, 10, 17, 27.... Input two nos. & 3rd term is the sum of previous two terms.
24. Tri-bonacii series: 1, 1, 2, 4, 7, 13... Forth term is the sum of previous three terms.
25. Keith number. For a 2 digit number third term is sum of previous two digits, and if term so
obtained at anytime = to the number then its is a Keith number. Exp: 14 is a Keith num. as 1 , 4 , 5, 9,
14. For a 3 digit number forth term is sum of previous three digits, and if term so obtained at
anytime is equal to the number then it is a Keith number. Exp: 197 is a Keith num. as 1, 9, 7, 17, 33,
57, 107, 197.
E. Duck number: If the number contains 0 as a digit. (Number should not start with 0)
F. Disarium number: sum of the digits^position value is equal to the number. Example: 135
Digits are 1,3 and 5. Position of 1 is 1, position of 3 is 2 and position of 5 is 3. Thus: 1^1 +
3^2 + 5^3 = 1+9+125 = 135
2
F. Niven Number: The number can be divided by the sum of its digits. Means sum of the digits
is the factor of the number. 1729 sum of its digits (1+7+2+9) is 19 and 1729 is divisible by 19.
F. Pall-Niven number: Number is divisible by sum of its digits and the reverse of the sum of the
digits. 1729 is divisible by both 19 and 91
26. Neon number: Sum of the digits of the square of the number = number. Exp. 9 square of 9 is
81 and sum of digits of 81 is 9 which is equal to the number.
27. Kaprikar number: Input a number (say 9). Find its square (81). Break the number from
middle and find sum of its left part and right part (8+1). If it is = the number then it is
kaprikar num. Other exps. 45 ( 45*45 = 2025 = 20+25 = 45), 297 (297*297= 88209 = 88+209=
297), an so on.
28. Antique number: Opposite of Kaprikar. Input number (say 2025. Find sum of left and right
part (20+25=45). Find square of number so obtained (45*45=2025) result is = to the inputted
num.
30. Unique digit numbers. Numbers in which digits are not repeated. 4256, 5687, 6942...
31. Unique words. Words in which characters are not repeated. Tiger, sky, education...
G. Pronic number: Number is the result of the product of two consecutive numbers. 6 is pronic
as 2*3 = 6. 20 is pronic as 4*5=20
G. Bouncy number: Number whose digits are neither in ascending order nor in descending
order, like 3654, 728973 etc. Bouncy numbers will always be of 3 or more digits.
G. Piglatin of a word. The first vowel occurring in the input word is placed at the start of
the new word along with the remaining alphabets of it. The alphabets present before
the first vowel are shifted at the end of the new word followed by “ay”. Example:
Piglating of – WRONG will be ONGWRAY, PARIS become ARISPAY, AMAZON
become AMAZONAY
G. Obtain Piglatin as follows: WRONG becomes ONGWRMID (MID is joined at the end
if the first vowel is found some were in the middle). INDIA become INDIAFST (FST
is joined at the end if the word starts with a vowel). SKY becomes SKYNON (NON is
added at the end if the word does not contain any vowel)
G. Input a word and check if it is a palindrome. If not then obtain a palindrome word by
joining it with its reverse. Example : CAT become CATTAC
G. Input a word and obtain a new word by joining it with its reverse as given below:
DOG be comes DOGOD, DOGEE becomes DOGEGOD, TOO become TOT
33. Cyclic number: An integer when multiplied with first N natural numbers (where N is count of
digits of the number) then each result so obtained will contain same digits in all the results. Exp.
142857 is cyclic. It has 6 digits so 142857 * 1 = 142857, 142857 * 2 = 285714, 142857 * 3 = 428571,
142857 * 4 = 571428, 142857 * 5 = 714285, 142857 * 6 = 857142. All results contain same digits.
3
34. Hamming distance of any two binary numbers is the count of difference of bits of two binary
numbers. Hamming distance of 101101 and 1110010 is 6 as bits differ at six places.
35. Input a number and print all consecutive numbers that adds up to give that number.
Example 15 Output: 1+2+3+4+5, 4+5+6, 7+8 all adds up to 15
36. WAP to input a string and check if it is a snow ball string. In a snow ball string the first word
has 1 char, 2nd word two chars, 3rd word three chars, 4th word four characters and so on. Exp.: “I am
not good going things .......” , I am the best dance master, i am the best motor runner...
37. 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 which 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 digitd is equal to 1. For 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 frequency, in the
format specified below:
38. Write a program to declare a square matrix A[][] of order M X M. M should be greater than 2
and less than 10. Display an appropriate message for invalid input. Perform the following task:
a) Display the original matrix
b) Check if the given matrix is symmetric or not. If the element of the i th row and j th column is
same as element of the j th row and i th column.
c)Find the sum of the left and right diagonal of the matrix and display them
Example
123 The given matrix is symmetric (2=2, 3=3, 5=5)
245 Sum of the left diagonal=11 (1+4+6)
356 Sum of the right diagonal=10 (3+4+3)
39. Write a program to enter values in a a double dim array of 4 rows and 5 cols. Display the
array in a matrix form along with the maximum number of each row and minimum number of each
column.
40. Write a program to print the give series and also print the sum of series…up-till N
0/1 – 1/2 + 1/3 – 2/4 – 3/5 + 5/6 – 8/7 + 13/8 – 21/9 +……. Nth Fibonacci term /N
41. Input a limit and print the following pattern: Example : limit = 4 (do not use arrays)
Output: 4 5 6 7 6 5 4 Limit = 5 5 6 7 8 9 10 9 8 7 6 5
3 4 5 4 3 4 5 6 7 8 7 6 5 4
2 3 2 3 4 5 6 5 4 3
1 2 3 4 3 2
1 2 1
0
42. Number Entered is 87. Step 1 87 + 78 = 165. Step 2 165 + 561 = 726. Step 3 726 + 627
= 1353. Step 4 1353 + 3531 = 4884. Palindrome 4884 obtained in 4
Step(s)
4
43. Fill a M x N matrix with first MxN prime numbers greater than the number X inputed.
44. Print first N perfect squares greater than number X inputed by user. X=14 and N=5 then
output is: 16, 25, 36, 49, 64
45. Input two dates. Check if both are valid. Then find the difference between two dates in
number of days. Taking 1 year = 360 days, month as 30 days find number of years, months, weeks
and days.
46. Input number of days (1-366) and year. Find the date in dd/mm/yy format. Input N days
(less than 300) and find the date after N days.
47. Input a valid date in DD/MM/YYYY format and the first day of the year. Find and print the
day on the given date.
48. Arrange the rows of a M x N array in descending order. Print the Old and the new matrix.
49. Input a number 1 to 100000 and print it in words. 1542 One thousand five hundred forty two
50. Input a decimal number and print it in binary, octal and hexadecimal. Also Input a number in
binary, octal or hexadecimal (as string) and print the equivalent decimal number.
51. Write a program to count and print all “Armstrong like” numbers between a given range M
and N. Armstrong like numbers are equal to the sum of cubes of its three parts. Example: 165033 =
16^3 + 50^3 + 33^3 Example: 166500333 = 166^3 + 500^3 + 333^3
52. Write a program to find and print the terms and the sum of the following series:
53. Input a sentence. Print the original sentence and the sentence after arranging the words in
alphabetic order.
54. Input a sentence. Print the original sentence and the sentence after arranging the words in
descending order of its count of vowels. If word contains equal number of vowels then arrange
words alphabetically. If words contain no vowels then arrange words according to length of words. If
length is same do not change the order.
Example : Input : “THE WILD ELEPHANT CANNOT TRY TO JUMP HIGH IN SKY”
Count of vowels : 1 1 3 2 0 1 1 1 1 0
55. Input a paragraph having sentences. A sentence ends with a FULL STOP(.), QUESTION MARK
(?) or with an EXPLANATION MARK (!). for the sentence at odd positions each word is reversed and
for sentence at even place characters of each word is shifted by 3 places. Example : Input : “IS IT
RAINING? THE OX IN THE ZOO! TIGER IN THE BUSH. TRY IT NOW.” OUTPUT : SI TI GNINIAR? WKH RA
LQ CRR! REGIT NI EHT HSUB. WUB LW QRZ.
56. An ISBN ( International Stanadar Book Number) is a ten digit code which uniquely identifies a
book. The first nine digits represent the Group, Publisher and Title of the book and the last digit is
used to check whehter ISBN is correct or not. Each of the first nine digits of the code can take a value
between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by
writing the last digit of the code as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times
5
the second digit, plus 8 times the third and so on until we add 1 time the last digit. If the final
number leaves no remainder when divided by 11, the code is a valid ISBN. For example:
02011003311 = 10*0 + 9*2 + 8*0 + 7*1 + 6*1 + 5*0 + 4*3 + 3*3 + 2*1 + 1*1 = 55
Since 55 leaves no remainder when divisible by 11, hence it is a valid ISBN.
56. A palindrome is a word that may be read the same way in either direction. Accept a sentence in
UPPER CASE which is terminated by either ".", "?", or "!". Each word of the sentence is separated by
a single blank space.
Perform the following taks:
(a) display the count of palindromic words in the sentence.
(b) Display the palindromic words in the sentence.
Example of palindromic words: MADAM, ARORA, NOON
57. Input a sentence terminated by a full stop. Words can be separated with more than one
spaces. Find and print the frequency of each word present in the sentence. Also print the count of
words (with out recounting duplicate words) Print the words in ascending order of their frequency
else in alphabetic order. Example Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.
OUTPUT: Total number of words (removing duplicate words) : 8
WORD/FREQUENCY: A=1, EASY=1, IT=1, PROGRAM=1, STRING=1, YES=1, THIS=2, IS=3
58. Given a square matrix list [ ] [ ] of order 'n'. The maximum value possible for 'n' is 20. Input
the value for 'n' and the positive integers in the matrix and perform the following task:
1. Display the original matrix
2. Print the row and column position of the largest element of the matrix.
3. Print the row and column position of the second largest element of the matrix.
4. Sort the elements of the rows in the ascending order and display the new matrix.
59. A sentence is terminated by either ".", "!" or "?" followed by a space. Input a piece of text
consisting of sentences. Assume that there will be a maximum of 10 sentences in a block.
Write a program to:
(i) Obtain the length of the sentence (measured in words) and the frequency of vowels in each
sentence.
(ii) Generate the output as shown below in Sample data:
INPUT HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.
OUTPUT
Sentence No. of Vowels No. of words
1 2 1
2 5 3
3 8 4
4 3 3
Also print a BAR chart of 1:3 for number of vowels and no. of words for each sentence.
6
60. Read a single sentence which terminates with a full stop(.). The words are to be separated with a
single blank space and are in lower case. Arrange the words contained in the sentence according to
the length of the words in ascending order. If two words are of the same length then the word
occurring first in the input sentence should come first. For both, input and output the sentence must
begin in upper case. Test your program for the following data and some random data.
INPUT : The lines are printed in reverse order.
OUTPUT : In the are lines order printed reverse.
INPUT : Print the sentence in ascending order.
OUTPUT : In the print order sentence ascending.
61. 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 than 20.
Allow the user to input positive integers into this matrix. Perform the following tasks on the matrix:
(a) Sort the elements of the outer row and column elements in ascending order using any standard
sorting technique.
(b) Calculate the sum of the outer row and column elements.
(c) Output the original matrix, rearranged matrix, and only the boundary elements of the rearranged
array with their sum. Test your program for the following data and some random data.
INPUT : M=3, N=3
ORIGINAL MATRIX REARRANGED MATRIX BOUNDARY ELEMENTS
1 7 4 1 3 4 1 3 4
8 2 5 9 2 5 9 2 5
6 3 9 8 7 6 8 7 6
SUM OF OUTER ROW AND OUTER COLUMN = 43
62. 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 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 for the following data and some random data.
63. An encoded text can be decoded by finding actual character for the given ASCII code in the
encoded message. Write a program to input an encoded text having only sequence of ASCII values
without any spaces. Any code or value which is not in the range (65-90 or 97-1 22 or 32-for space)
will be ignored and should not appear in the output message. It is assumed that none the additional
value is given in the coded text. Decode the encoded text and print in the form of sentence. The first
alphabet of each word must be in capitals and rest alphabets will be in smalls only. Any consecutive
sets of code 32 will be taken as only one blank space. The output should be exactly in the following
format. Sample test data: Input (coded text) : 10665771011153266797868
Output (decoded text) : James Bond
64. To input a string (precoded), coded by replacing each character with the character which
comes 'n' characters after it, and decode it using an input defining the number of characters to shift.
Sample data-
7
Enter the encoded string : FQNJSX%FWJ%HTRNSL%&&
How many characters to shift : -5
Decode message is : ALIENS ARE COMING !!
65. Write a program to input a string and print the following pattern: String = holiday
_
h_y
ho_ay
hol_day
holi_iday
holid_liday
holida_oliday
holiday_holiday
holida_oliday
holid_liday
holi_iday
hol_day
ho_ay
h_y
_
66. Input two words and check if they are anagram or not. Two words having same characters.
Example: DOG and GOD; TOT and POT are anagram words. TIGER WITER are not anagram.
67. Input a words having length <7 and print all possible combination of words.
Example: “AND” AND, ADN, NAD, NDA, DAN, DNA
Example: “96” 96, 69
69. Shift a given digit to the extreme right of the number. 701004 shift 0 becomes 714000
70. Add two 15 digit numbers. Each inputted number should be of 15 digits.
71. Write a overloaded function ORDER(int), ORDER(String), ORDER(int arr[]) that returns 0 if all
digits of the number or all characters of the word or all numbers of the array are in ascending order.
Function returns 1 if all digits of the number or all characters of the word or all numbers of the array
are in descending order. Function returns -1 if all digits of the number or all characters of the word
or all numbers of the array are in mixed order.
Q1. PSP number is a prime number whose square is a palindrome number. Example: 11
as square of 11 is 121 which is a palindrome number. You are required to input a range M
and N, where M is less than N, print appropriate message if M is greater than N. Count and
print all PSP numbers between M and N (both inclusive). Test your program: M=5 and N
=500 then output : 11, 101, 307 Count is: 3
Q2. VOW words are those words that contain all the 5 vowels of upper case i.e.
A,E,I,O,U. Write a program to input a string in upper case and print all the VOW words
present in the string. Also print the frequency of such words. Test your program taking the
8
following input: str=“The Higher Authorities of Automobile industries needs good
Education”
Output: Authorities, Automobile, Education Frequency of words = 3
Q3. A UNQ array is an array having non duplicate values. Thus an array having
{56,43,78,90} is and UNQ array as no value is repeated. Input numbers in a Double
dimension array having M rows and N columns and count the rows having UNQ numbers
and display proper message.
Q1. Input date as a string in “DDMMYYYY” format. Check string length should be 8. Then
check if the inputted date is a valid date. If valid print it in given format. INPUT
”23022017” OUTPUT Valid date : 23rd Feb. 2017
Q2. Input a square matrix of size M. Where M is >=3 and <=10. Then check if the matrix is
a ZeroDiago matrix or not. Matrix is ZeroDiago if all non diagonal elements are zero. Also
print the sum of elements of main diagonal and of secondary diagonal.
Q3. Input a string and shift each character by 13 places and shift each digit by 5 places in
circular manner. Spaces are replaced by till sigh (~) and other special characters remain
unchanged. INPUT 29 Ox & Zoo. OUTPUT 74~Bk~&~Mbb.
Q1. Input two dates of the same year in dd,mm,yy format and find the number of days
between these two dates.
Example 1: Date1 = 12.1.2000 Date2 = 15.3.2000 Then Number of days = 63 days
Example 2: Date1 = 5.2.2003 Date2 = 20.5.2003 Then Number of days = 104 days
Q2. Input a range M and N. Where M is less than N. Now print all unique digit numbers
between this range also print the frequency of such numbers that are printed. Unique digit
numbers do not have duplicate digits. Like 2589 is unique but 2686 is not unique.
Example1: M=2500 N=2545
Unique Digit Numbers in the range are: 2501, 2503, 2504, 2506, 2507, 2508, 2509, 2510,
2513, 2514, 2516, 2517, 2518, 2519, 2530, 2531, 2532, 2534, 2536, 2537, 2538, 2539, 2540,
2541, 2543. Frequency of Numbers: 25
Example2: M=1234 N = 1120 Output : Incorrect range. M should be less than
N
Q3. Input a string having maximum 15 words and print all the words having all the
vowels.
Example1: “The Higher Authorities of Automobile industries needs good Education”
Output: Authorities, Automobile, Education
Frequency of words = 3
Example2: “Good and proper education is required for the speedy and over all
development of any country”
Output: Error !! String contains more than 15 words.