0% found this document useful (0 votes)
42 views

II Assignment Class XII

Uploaded by

Saurav Tanti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

II Assignment Class XII

Uploaded by

Saurav Tanti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Computer Science Assignment-II

Submission Date: 16th December 2024

Question 1

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 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 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:

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 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:
INVALID INPUT

Example 4:

INPUT:
M=4
N=6

OUTPUT:
OUT OF RANGE

Question 3

The names of the teams participating in a competition should be displayed on a


banner vertically, to accommodate as many teams as possible in a single banner.
Design a program to accept the names of N teams, where 2 < N < 9 and display them
in vertical order, side by side with a horizontal tab (i.e. eight spaces).

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

Question 4

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

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 5

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 6

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:

1. Find the number of words beginning and ending with a vowel.


2. 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

Example 2

INPUT:
YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE
TODAY.

OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY

Example 3

INPUT:
LOOK BEFORE YOU LEAP.

OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 0
LOOK BEFORE YOU LEAP

Example 4

INPUT:
HOW ARE YOU@

OUTPUT:
INVALID INPUT

Question 7

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.

Example 2

INPUT:
N = 1193

OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME.

Example 3

INPUT:
N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME.

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/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.

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

You might also like