0% found this document useful (0 votes)
149 views43 pages

Computer Science Project Class 11

This document outlines a programming project to find the saddle point of a 2D array. It defines a saddle point as an element that is the minimum value in its row and the maximum value in its column. The program accepts a square 2D array of size n from the user, outputs the original array, and then checks each element to find the saddle point. If no saddle point exists, it will output "NO SADDLE POINT". Pseudocode is provided with steps to input the array, output the original array, iterate through the elements to check for a minimum row and maximum column value, and output the saddle point or message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views43 pages

Computer Science Project Class 11

This document outlines a programming project to find the saddle point of a 2D array. It defines a saddle point as an element that is the minimum value in its row and the maximum value in its column. The program accepts a square 2D array of size n from the user, outputs the original array, and then checks each element to find the saddle point. If no saddle point exists, it will output "NO SADDLE POINT". Pseudocode is provided with steps to input the array, output the original array, iterate through the elements to check for a minimum row and maximum column value, and output the saddle point or message.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

St.

Augustine’s day school

For Session 2020-2021

Name: Avishankar Sardar


Class: XI Section: A
Roll Number: 45
INDEX
S.No Date Topic
1 10.08.20 Question 1- Vowels and String Manipulation

2 12.08.20 Question 2- Twin Prime Numbers

3 14.08.20 Question 3-Upper Triangular Matrix

4 22.08.20 Question 4- Circular Prime

5 02.09.20 Question 5 - Array Boundary Elements

6 03.09.20 Question 6 - 2D Array in Ascending Order

7 08.09.20 Question 7 - Saddle Point of 2D Array

8 09.09.20 Question 8 - Spiral Program

9 11.09.20 Question 9 - Matrix Multiplication

10 18.09.20 Question 10 - Magic Square


PROJECT QUESTION 1
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:
(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.

Algorithm
Step 1: Start
Step 2: Setup to assign a given sentence by the user to a variable
Step 3: Checking for special characters like ‘.’,’?’,’!’ etc. If found
going to Step 9.
Step 4: Iterating a loop to return all the characters.
Step 5: If a vowel is found then storing its index and checking for a
vowel at the end of that word if true then Step 6, if false then
Step:7.
Step 6: If a vowel at the end is found then storing it in a String
‘vowel’ and incrementing a counter ‘cc’.
Step 7: No vowel is found then storing the word in a String
‘consonant’.
Step 8: Displaying the counter and the concatenated Strings of
‘vowel’ and’ consonant’.
Step 9: Stop.
CODE
VARIABLE DESCRIPTION TABLE

Name Type Function


str String Stores User’s Input

str_vow String Stores Vowels

str_con String Stores Consonants

fin String Stores The Desired String

ch char Marks the starting point of a word

ch2 char Marks the ending point of a word

l int Stores the length of the String

i int Iterates the loop

j int Iterates the loop

n int Counts number of Vowels


OUTPUTS
PROJECT QUESTION 2
Write a Program in Java to print all the Twin Prime numbers within a
given range [the range needs to be asked from the user].
Note: Twin Prime numbers are a pair of numbers which are both prime
and their difference is 2.
Example: Twin Prime numbers in the range 1 to 100 are:
(3,5) (5,7) (11,13) (17,19) (29,31) (41,43) (59,61) (71,73)

Algorithm
Step 1: Start
Step 2: Setup to assign the lower and the upper limit from user.
Step 3: Checking if the lower limit is greater than upper limit or if
both are equal. If true then going to Step 9.
Step 4: Iterating a loop to generate all numbers from the lower
limit to the upper limit by an increment of one.
Step 5: Checking if the number returned by Step 4 is Prime or not.
Step 6: If Step 5 is true then checking if the number with an
increment of 2is prime or not
Step 7: If Step 5 is true then printing both numbers as twin prime
numbers.
Step 8: Returning to Step 4 if upper limit not satisfied.
Step 9: Stop.
CODE
VARIABLE DESCRIPTION TABLE

Name Type Function


fl int Stores Lower Limit
ll int Stores Upper Limit
fl2 int Stores the Second Prime Number
i int Iterates the loop and stores the first
prime number
ch boolean Stores whether number is prime or not
c int Counts number of divisor
a int Stores the number to be checked

OUTPUTS
PROJECT QUESTION 3
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.
Example:
5307
0198
0046
0002

Algorithm
Step 1: Start
Step 2: Setup to assign the memory of the Array and elements of
the Array from the User.
Step 3: Displaying the Array entered by the User.
Step 4: Checking for each element below the main diagonal is
zero or not.
Step 5: If Step 4 is false then displaying appropriate message and
going to Step 7.
Step 6: If Step 4 is True then displaying appropriate message and
going to Step 7.
Step 7: Stop.
CODE
VARIABLE DESCRIPTION TABLE

Name Type Function


m int Stores size of array
A[ ] int Integer Array to store the elements
fl2 int Stores the Second Prime Number
i int Iterates the loop
j int Iterates the loop

OUTPUTS
PROJECT QUESTION 4
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. Write a program to display all the
circular prime numbers from 1 to 200.

Algorithm
Step 1: Start
Step 2: Setup to iterate all numbers from 1 to 200
Step 3: Checking if a number is Prime or not.
Step 4: If Step 3 is true then checking number of digits. As loop is
from 1 to 200 maximum three digit number is possible.
Step 5: If number of digits is 1 then displaying the number directly.
Step 6: If number of digits is 2 then checking if the number in
reverse order is Prime and displaying.
Step 7: If number of digits is 3 then checking if the reverse and
first and last digit swapped number is true or not.
Step 8: If Step 7 is true then displaying the number.
Step 9: Stop.
CODE
VARIABLE DESCRIPTION TABLE

Name Type Function


n,d int Stores number of digits

b int Stores the last digit of the number

a int Stores the number

i int Iterates the loop

j int Iterates the loop

sw int Returns the swapped number

rev int Stores reversed number

cc int counter

d,ch,ch1 boolean Stores whether a number is prime or


not

OUTPUT
PROJECT QUESTION 5
Write a Program in Java to input a 2-D array of size ‘m*n’
and print the given array and its boundary (border)
elements. For Example
Input: - Output:-
1 2 3 4 5 1 2 3 4 5
6 7 8 9 10 6 10
11 12 13 14 15 11 15
16 17 18 19 20 16 17 18 19 20

Algorithm
Step 1: Start
Step 2: Setup to assign the memory of the Array and elements of
the Array from the User.
Step 3: Displaying the Array entered by the User.
Step 4: Iterating a loop to generate all the elements.
Step 5: Checking if an element lies in the boundary or not.
Step 6: If Step 5 is True then displaying the element.
Step 7: If Step 5 is False then checking for next element until all
elements are checked.
Step 8: Stop.
CODE
VARIABLE DESCRIPTION TABLE

Name Type Function


n int Stores number of Column

m int Stores number of Rows

a[ ] int Integer Array to store the elements

i int Iterates the loop and determines


boundary elements
j int Iterates the loop and determines
boundary elements
OUTPUTS
Project Question 6:

Sort a Two Dimensional (2D) Array in ascending order.

Algorithm
Step 1: Start
Step 2: Input the 2D array of ‘m’ rows and ‘n’ columns.
Step 3: Print the original array.
Step 4: Create a 1D array of size ‘m*n‘
Step 5: Save all elements of 2D array into 1D array (i.e.
Converting a 2D array into a 1D array)
Step 6: Sort the 1D array using bubble sorting technique.
Step 7: Save the elements of the sorted 1D array back to the 2D
array.
Step 8: Stop.
CODE
Variable Description Table

Name Type Function


n int Stores number of Column

m int Stores number of Rows

a1 int Integer 1d Array to store the sorted


elements
a[ ] int Integer 2d Array to store the elements

i int Iterates the loop and determines


boundary elements
j int Iterates the loop and determines
boundary elements
OUTPUT
Project Question 7:
Write a program to declare a square matrix A[ ][ ] of order ‘n’. Allow the
user to input positive integers into this matrix. Perform the following
tasks on the matrix:
(i) Output the original matrix.
(ii) Find the SADDLE POINT for the matrix. If the matrix has
no saddle point, output the message “NO SADDLE
POINT”.
[Note: A saddle point is an element of the matrix such that it is
the minimum element for the row to which it belongs and
the maximum element for the column to which it belongs. Saddle point
for a given matrix is always unique.]
Example:
In the Matrix
456
789
513
Saddle point = 7 because it is the minimum element of row 2 and
maximum element of column 1.
Algorithm
Step 1: Start
Step 2: Input the 2D array of ‘m’ rows and ‘n’ columns.
Step 3: Print the original array.
Step 4: Iterate a loop to generate all the elements of an array.
Step 5: Finding the minimum element of the row.
Step 6: Finding if the element which fulfills Step 5 is the maximum
number in its column.
Step 7: If Step 6 is true then displaying the number as Saddle
point number.
Step 8: If Step 6 is false then displaying that this matrix has no
saddle point.
Step 9: Stop.
CODE
Variable Description Table

Name Type Function


n int Stores number of Column

m int Stores number of Rows

a[ ] int Integer 2d Array to store the elements

i int Iterates the loop and determines


boundary elements
j int Iterates the loop and determines
boundary elements
rm int Stores the least element of a row

cl int Stores the number of a row

sp boolean Stores whether rm is the maximum


element in its column or not
OUTPUT
Program Question 8
Write a Program in Java to fill a square matrix of size ‘n*n” in a circular
fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as
input.
For example: if n = 4, then n*n = 16, hence the array will be filled as
given below.
1 2 3 4
12 13 14 5
11 15 16 6
10 9 8 7

Algorithm
Step 1: Start
Step 2: Input the size of 2D array
Step 3: Print the first row and then print the last column.
Step 4: Then printing last row from right to left.
Step 5: Then printing first column down to up.
Step 6: Repeating if all the spaces are not full.
Step 7: Stop.
CODE
Variable Description Table

Name Type Function


n int Stores Size

a[ ] int Integer 2d Array to store the elements

i int Iterates the loop

j int Iterates the loop

k int Checks the number of elements


generated
c1 int First column counter

c2 int Second column counter

r1 int First row counter

r2 int Second row counter


OUTPUT
Program Question 9
Write a Java Program to multiply two matrices. Create two 2D Arrays of
user’s choice, multiply and store the result in a 3rd array. Display all the
arrays in array format.

Algorithm
Step 1: Start
Step 2: Input the first 2D array of ‘m’ rows and ‘n’ columns.
Step 3: Input the second 2D array of ‘m1’ rows and ‘n1’ columns.
Step 4: Print the two arrays
Step 5: Finding compatibility for multiplication (i.e. if n==m1)
Step 6: If Step 5 is true then proceeding else going to Step 9.
Step 7: Multiplying the first two arrays and storing it in a new
array.
Step 8: Displaying the third array.
Step 9: Stop
CODE
Variable Description Table

Name Type Function


n int Stores number of Column for first
Array
m int Stores number of Rows for First array

m1 int Stores number of Column for second


Array
n1 int Stores number of Rows for second
array
b[ ] int Integer 2d Array to store the elements

a[ ] int Integer 2d Array to store the elements

c[ ] int Integer 2d Array to store the elements


after multiplication
i int Iterates the loop and determines
boundary elements
j int Iterates the loop and determines
boundary elements
OUTPUTS
Program Question 10
A square matrix is said to be a Magic Square, if the sum of each row,
each column and each diagonal is same. Write a program to enter an
integer number ‘n’. Create a magic square of size ‘n*n’. Finally, print
the elements of the matrix as Magic Square.

Algorithm

Step 1: Start
Step 2: Input the size of 2D array
Step 3: Checking if the size is odd or even.
Step 4: If even then printing a normal matrix.
Step 5: Then swapping elements of primary and secondary
diagonals.
Step 6: If odd then filling the elements upwards then right and
incrementing if rows and columns are violated
Step 7: Displaying the Generated Magic Square.
Step 8: Stop.
CODE
Variable Description Table

Name Type Function


n int Stores Size
a[ ] int Integer 2d Array to store the elements
i int Iterates the loop
j int Iterates the loop
k int Checks the number of elements
generated
t int Helps in swapping

OUTPUTS

You might also like