Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

INDEX

Sr. Particulars Date Page


No. No.

Functions

1 Modius Function 5/04/2021


2 Kaprekar Number 6/04/2021
3 Circular Prime 12/04/2021
4 Fascinating Number 13/04/2021
5 Permutation and Combination of two numbers 14/04/2021
6 Prime - Adam Number 16/04/2021
7 Odious Number 20/04/2021

Conditional Statement and Iterations


8 Triangular Number 22/04/2021
9 Euler Number 29/04/2021
10 Day and Month Program 30/04/2021
11 Box Program 30/04/2021

Strings
12 Pig Latin Program 8/06/2021
13 Remove Duplicate Characters Program 11/06/2021
14 Word Beginning and ending with Vowels Program 14/06/2021
15 Anagram Program 16/06/2021
16 Caesar Cipher Program 22/06/2021
17 Magic String 28/06/2021
18 Display banner vertically Program 2/07/2021

Single Dimensional Array


19 Menu Driven Program 5/07/2021
1) Linear Search Program
2) Binary Search Program
20 Menu Driven Program 7/07/2021
1) Bubble Sort
2) Section Sort
3) Insertion Sort

21 Accept Date using String 09/07/2021


22 Merge two Arrays 12/07/2021

Two Dimensional Array


23 Transpose of Matrix Program 20/07/2021
24 Square Matrix Program 23/07/2021
25 Sorting Matrix Row wise Program 27/07/2021
26 Spiral in Square Matrix Program 28/07/2021
27 Game Program 29/07/2021
Date File Handling
28 Creating / Reading Text File 10/08/2021
29 Merging two text files 11/08/2021

Data Structure
30 Stack Program 8/09/2021
31 Queue Program 10/09/2021

Recursion
32 Factorial of a number 14/09/2021
33 Reverse a string using recursion 16/09/2021
34 Searching using Binary Search Technique Program 17/09/2021

Application Based Program

1. Acknowledgements 14/04/2021
2 Program Description
3. Name of your application program (coding and output)
4. Limitations
5. Bibliography
Details of Programs:

1) A MOBIUS function M(N) returns the value -1 or 0 or 1 for a natural number (N) by the
following conditions are defined:
When,
M(N) = 1 if N = 1
M(N) = 0 if any prime factor of N is contained in N more than once.
M(N) = (-1)P if N is the product of ‘P’ distinct prime factors.
Write a program to accept a positive natural number (N) and display the MOBIUS result
with proper message.

Design your program which will enable the output in the format given below:

Sample 1:
INPUT: 78
OUTPUT:
78 = 2 × 3 × 13
NUMBER OF DISTINCT PRIME FACTORS = 3
M(78) = -1

Sample 2:
INPUT: 34
OUTPUT:
34 = 2 × 17
NUMBER OF DISTINCT PRIME FACTORS = 2
M(34) = 1

Sample 3:
INPUT: 12
OUTPUT:
12 = 2 × 2 × 3
DUPLICATE PRIME FACTORS
M(12) = 0

Sample 4:
INPUT: 1
OUTPUT:
1=1
NO PRIME FACTORS
M(1) = 1

2) 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 to output the number of Kaprekar numbers in the specified range along with their
values in the format specified below.
The following steps can be used to check whether a number is Kaprekar number or
not.
(i) Find square of the number(n).
(ii) Divide the square of the number (n) in two parts in such a way that both the
parts have equal number of digits (if square number has even number of digits).
In case, square of the number has odd number of digits then divided the number
in two parts such that left part may have the number of digits one less than the
right part.
(iii) Add both the parts together.
(iv) If sum obtained is equal to the original number(n), then the given number is said
to be Kaprekar number.

Example 1:
Input number = 45
Square of the number = 2025
Left part = 20
Right part = 25
Sum of both parts = 45
Hence, 45 is a Kaprekar numbers.
Some of Kaprekar numbers are : 1, 9, 45, 55, 99, 297, 703, 999
Frequency of Kaprekar numbers is : 8

3) 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 (one) and itself.

Example 1:
Sample Input : N = 131
Sample Output:

131
311
113
Hence, 131 is a circular prime.

Example 2:
Sample Input : N = 197
Sample Output:
197
971
719
Hence, 197 is a circular prime.

Example 3:
Sample Input : N = 29
Sample Output:
29
92
Hence, 29 is not a circular prime.

4) Write a program to input a number and check whether it is a Fascinating Number or


not.

Fascinating Numbers: Some numbers of 3 digits or more exhibit a very interesting


property. The property is such that, when the number is multiplied by 2 and 3, and both
these products are concatenated with the original number, all digits from 1 to 9 are
present exactly once, regardless of the number of zeros.

Example 1:
Sample Input: N = 192
192 x 1 = 192
192 x 2 = 384
192 x 3 = 576

Concatenating the results: 192384576


It could be observed that ‘192384576’ consists of all digits from 1 to 9 exactly once.
Hence, 192 is Fascinating Number.
(Few Fascinating Numbers are 192,219, 273, 327, 1902, 1920, 2019, etc)

5) Permutation and combination of two numbers ‘n’ and ‘r’ are calculates as:
n
Pr = !n .
!(n – r)
n
Cr = !n .
!(n – r) * !r

Where Permutation is denoted as nPr and combination is denoted as nCr. The nPr means
permutation of ‘n’ and ‘r’ & nCr means combination of ‘n’ and ‘r’.
Write a program to calculate and display the number of permutation and combinations
of two numbers ‘n’ and ‘r’ by using the above formula.

Example 1:
Sample Input:
Enter the value of n: 11
Enter the value of r: 10

Sample Output:
n
Pr = 39916800
n
Cr = 11

6) 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.
Eg: 2, 3, 5, 7, …..etc.
Adam Number : The square of a number and the square of its reverse are reverse
to each other.
Eg: if n = 13 and reverse of ‘n’ = 31, then
(13)2 = 169
(31)2 = 961 which is the 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

7) An Odious number is a positive whole number. Which has odd number of 1’s in its
Binary equivalent.

Example 1: Binary equivalent of 8 is 1000. Which contains odd number of 1’s. So, 8
is Odious number.
Example 2: Binary equivalent of 13 is 1101. Which contains odd number of 1’s. So,
13 is Odious number.
Example 3: Binary equivalent of 9 is 1001. Which contains even number of 1’s. So, 9
is not Odious number.

A few Odious numbers are : 2, 4, 7, 8, 11, 13, etc.

Design a program to accept a positive whole number. Find the binary equivalent of the
number and count the number of 1’s in it and display whether it is an Odious number or
not with an appropriate message. The proper error message should be displayed for
the negative input.

Test your program with the sample data and some random data:

Example 1: INPUT: 11
OUTPUT: BINARY EQUIVALENT = 1011
NUMBER OF 1’S = 3
11 IS AN ODIOUS NUMBER

Example 1: INPUT: 15
OUTPUT: BINARY EQUIVALENT = 1111
NUMBER OF 1’S = 4
15 IS NOT AN ODIOUS NUMBER

Example 1: INPUT: -17


OUTPUT: INVALID INPUT
8) A class Numbers contains the following data members and member functions to check
for triangular numbers. [A Triangular number is formed by the addition of a consecutive
sequence of integer starting from 1].

For Example: 1 + 2 = 3, 1 + 2 + 3 = 6, 1 + 2 + 3 + 4 = 10, 1 + 2 + 3 + 4 + 5 = 15

Therefore, 3, 6, 10, 15, etc are Triangular Numbers.


Class Name : Numbers
Data Members/Instance :
Variables
n : integers to be checked for whether it is triangular or
not
Member Functions :
void getnum() : to accept integer n
int check(int) : to check if ‘n’ is triangular
void dispnum() : to display message whether ‘n’ is triangular or not

Specify the class Numbers giving details of the functions void getnum(), int
check(int) and void dispnum(). The main function need to be written.

9) The Euler Number e is used as the base of natural logarithm.

It can be approximated using the formula:


e = 1 + 1 / 1! + 1 / 2! + 1 / 3! + … 1 / n!

Write a program in Java that approximates e using a loop that terminates when the
difference between two successive values of e differ by less than 0.0000001.

10) Input a positive integer n>=5 digits, the computer should reject if less than five digits
Design a class Convert to find the date and the month from a given day number for a
particular year.

Example: If day number is 64 and the year is 2020, then the corresponding date would
be: March 4, 2020 i.e. (31 + 29 + 4 = 64).

Some of the members of the class are given below:

Class name: Convert


Data members/instance variables:
n: integer to store the day number.
d: integer to store the day of the month (date).
m: integer to store the month.
y: integer to store the year.
Methods/Member functions:
Convert(): constructor to initialize the data members with legal initial values.
void accept(): to accept the day number and the year.
void dayToDate(): converts the day number to its corresponding date for a particular
year and stores the date in ‘d’ and the month in ‘m’.
void display(): displays the month name, date and year.

Specify the class Convert giving details of the constructor, void accept(), void
dayToDate() and void display(). Define a main() function to create an object and call
the functions accordingly to enable the task.

11)A company manufactures packing cartoons in 4 sizes i.e cartons to accommodate 6,


12, 24, 48 boxes. Design a program to accept the number of boxes to the packed(n)
by the user. Maximum up to 1000, and display the breakup of cartons. Preference
should be given to highest capacity and if the boxes left are less than 6 an extra 6 box
sized carton should be used.

12)Write a program that encodes a word into Piglatin. To translate a word into Piglatin,
convert the word into Piglatin, convert the word into uppercase and then place the first
vowel of the original word as the start of the new word along with the remaining
alphabets. The alphabets before the vowel being shifted towards the followed by “ay”.

Eg: Enter a word:


London

The Piglatin form is :ONDONLAY

13)Write a program to input a String and remove the duplicate characters.

Eg:
Enter any word: mississipi
Word after removing duplicate characters are : misp

14)Write a program to accept a sentence which may be terminated by either “.” , “,” , “?” or
“!” only. The words may be separated by more than one space and convert to
uppercase.
Perform the following tasks:
i) Find the number of words beginning and ending with vowel.
ii) Display these words first followed by the other words.

15)The words that are made with the combinations of the letters present in the original
word are called Anagram. Write a program to accept two words and check whether
they are Anagram or not.

Example 1:
Sample Input:
Enter first letter: FLOW
Enter Second letter: WOLF
Hence, both are anagram words.

Few anagram words are: Silent – Listen, Triangle – integral, etc

16)Caesar Cipher is an encryption technique which is implemented as ROT13. 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. Write a program to
accept a plain text of length L, where L must be greater than 3 and less than 100.

Eg: Enter a string: Hello


The new string is : URYYB

17)Write a program to accept a word. Pass the word to a method Magic(String word). If
Checks the presence of the consecutive letters within the word. If two letters are
consecutive at any position, then it displays “It is a magic string” otherwise, “ It is not a
magic string”.

Example 1:
Samle Input:
Enter a word: ABDOMEN
Sample Output:
Magic String

Example 2:
Samle Input:
Enter a word: COMPUTER
Sample Output:
Not a Magic String

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

SAMPLE INPUT: N = 3

Team 1: Emus
Team 2: Road Rols
Team 3: Coyote

SAMPLE OUTPUT:
E R C
m o o
u a y
s d o
t
R e
o
l
s

Example 2:

SAMPLE INPUT: N = 4

Team 1: Royal
Team 2: Mars
Team 3: De Rose
Team 4: Kings

SAMPLE 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

19)Write a menu driven program to perform


(i) Linear Search on a user – inputted array.
(ii) Binary Search on a inputted array

20)Write menu driven program to perform


(i) Selection Sort on an inputted array
(ii) Bubble Sort on an inputted array
(iii) Insertion Sort on an inputted array

21)Write a program to accept a date in the string format dd/mm/yyyy and accept name of
the day on 1st of January of the corresponding year. Find the day for the given date:

Example 1:
Sample Input:
Date: 05/07/2001
Day on 1st January : MONDAY

Sample Output:
Day on 05/07/2001: THURSDAY

Example 2:
Sample Input:
Date: 04/09/1998
Day on 1st January : THURSDAY

Sample Output:
Day on 04/09/1998: FRIDAY

Example 3:
Sample Input:
Date: 06/12/2000
Day on 1st January : SATURDAY

Sample Output:
Day on 06/12/2000: WEDNESDAY
22)Write a program to input two single dimensional arrays A[n] and B[m]. Merge both the
arrays in C[n+m].

Example:
Sample Input:
Enter the size of first array: n=3
Enter the size of second array: m=5

Enter elements in the first array:


1
8
6

Enter elements in the second array:


4
10
2
9
45
Sample output:
After merging both the arrays:
1
8
6
4
10
2
9
45

23) Write a program to display the Transpose of the matrix taken as input from the user.

Example 1:
Sample Input:
Enter the size for Row = 3
Enter the size for Col = 3

Enter the elements:


1
2
3
4
5
6
7
8
9

Sample Output:
The original matrix is:
1 2 3
4 5 6
7 8 9

Transpose of Matrix is:

1 4 7
5 5 8
3 6 9

24)Write a program to declare a square matrix of order mXm where m is the number of
rows and columns such that ‘m’ must be greater than 2 and less than 10. Display an
appropriate message for wrong value. Input the elements as integers and perform the
following tasks:

(i) Display the original matrix.


(ii) Rotate the matrix 90 degree clockwise.
(iii) Find the sum of the four corners of the matrix.

25)Write a program to declare a matrix A[ ] [ ] of order (M x N) where ‘M’ is the number or


rows and ‘N’ is the number of columns such as the value 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:
(i) Display the original matrix
(ii) Sort each row of the matrix in ascending order using any standard sorting
technique.
(iii) Display the changed matrix after sorting each row.
Test your program for the following data and some random data:

Example 1:

Sample Input: M = 4
N=3

ENTER ELEMENTS OF MATRIX

11 -2 3
5 16 7
9 0 4
3 1 8

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

Sample Input: M = 3
N=3

ENTER ELEMENTS OF MATRIX

22 5 19
7 36 12
9 13 6

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

Sample Input: M = 11
N=5

Sample Output: MATRIX SIZE OUT OF RANGE

26)A Square matrix is the matrix in which number of rows is equal to the number of
columns. Thus, a matrix of order n*n is called a Square Matrix.
Write a program to fill the numbers in a circular fashion (clockwise) with natural
numbers from 1 to n2, taking n as an input.

Example 1:
Sample Input: n = 4
Sample Output: n2 = 16, then the array is filled as:

1
2 3 4
13
12 14 5
16 15 6
11
10 8
9 7
27)Write a program to design your own game. (Eg. Tic-tac-toe, X’s and 0’s, etc)

28)Write a program using text file concept for the following:


(a) Create a text file “data.txt” to input and store N sentences.
(b) Read the above text file to read sentences and print the sentence and number of
words in each sentence. Print output in two columns.

// The following is a computer generated output (the three sentences will be


stored in “data.txt”):

Input total number of sentences to store :3


Input a sentence : A fox was running
Input a sentence : This is an engineering college
Input a sentence : It is nice

//The following is a computer generated output:


Sentence Number of words

A fox was running 4


This is an engineering college 5
It is nice 3

29)Write a program to merge the files “test1.txt” and “test2.txt” into a new file “PAN.txt”
in such a way that name of person and its pan number should be stored as one string
with only one space between name and pan number.

30)A Stack is a linear data structure which enables the user to add and remove integers
from one end only. i.e. on the TOP, using the concept of LIFO (Last In First Out).
Define a class Stack with the following details:

Class name : Stack


Data Members / Instance Variables :
stk[ ] : integer array to hold maximum 50 elements
cap : integer to store the maximum size of the array/stack.
top : integer to point the index of the topmost element of the stack.
Member functions / Methods:
Stack(int nn) : parameterized constructor to initialize cap = nn and top = -1.
void Push(int num) : to push or insert argument num at the top location, if
possible, otherwise display a message “Stack Overflow”.

void Pop() : to pop or remove an integer from the top of the stack, if
possible and print it, otherwise display a message “Stack
Underflow”.
void display() : to print the elements present in the stack, if possible,
otherwise display a message “Stack Underflow”.

Specify the class Stack giving details of the constructor the functions void Push(int),
void Pop() and void display(). Write a main() function to create object and call the
functions accordingly to enable the task.
Sample Input and output:
Enter total numbers of elements for Stack: 3
Enter elements :
7
56
12

Do you want to pop or deleted and element from stack (y/n):


If ‘y’ or ‘Y’ then
The popped or deleted integer is = 12
The elements in the stack are as below:
7
56
else if ‘n’ or ‘N’ then
The elements in the stack are as below:
7
56
12

31)Queue is a linear data structure which enables the user to add integers from rear end
and remove integers from the front end, using FIFO (First In First Out) principle.
Define a class Queue with the following details:

Class name : Queue


Data Members / Instance Variables :
arr[ ] : integer array to hold maximum 50 elements
cap : integer to store the maximum size of the array/queue
front : integer to point the index of front end.
rear : integer to point the index of rear end.
Member functions / Methods:
Queue(int nx) : constructor to initialize cap = nx, front = 0 and rear = -1.
void Push(int num) : to push or insert argument num at the rear location, if
possible, otherwise display a message “Queue Overflow”.

void Pop() : to pop or remove an integer from the front of the queue, if
possible and print it, otherwise display a message “Queue
Underflow”.
void show() : to print the elements present in the queue, if possible,
otherwise display a message “Queue Underflow”.

Specify the class Queue giving details of the constructor the functions void
Push(int), void Pop() and void show(). Write a main() function to create object and
call the functions accordingly to enable the task.

Sample Input and output:


Enter total numbers of elements for Queue: 3
Enter elements :
7
56
12
Do you want to pop or deleted and element from Queue (y/n):
If ‘y’ or ‘Y’ then
The popped or deleted integer is = 7
The elements in the queue are as below:
56
12
else if ‘n’ or ‘N’ then
The elements in the queue are as below:
7
56
12

32)The factorial of a number ‘n’ is calculated as:


n! = n * (n-1) * (n-2) * (n-3) * ………… * 1.
A class Factorial is declared with the following details:

Class name : Factorial


Data Members / Instance Variables :
n : to store a integer number greater than zero
f : to store the factorial of a number entered by the user
Member functions / Methods:
Factorial() : a constructor to assign 0 to n
int fact(int num) : to find and return the factorial of num (num > 0) using
recursive technique otherwise, it should return 1 if num =0
void get(int x) : to assign x to n and by invoking function fact() store the
factorial of n into f. Display the result with a suitable message.

Write the main method to create an object to class Factorial and call the function
get(int).

Example 1:
Sample Input:
Enter a number for its factorial: 12

Sample Output:
The factorial of 12 is 479001600

33)A class Revstr defines a recursive function to reverse a string and check whether it is
Palindrome or not. The details of the class are given below:

Class name : Revstr


Data Members / Instance Variables :
str : to store string
Revst : stores the reverse string
Member functions / Methods:
void getStr() : to accept the string
void recReverse(int) : to reverse the string using Recursive Technique
void check() : to display the original string, its reverse and check whether
the string is Palindrome or not.

Specify the class Revstr giving the details of the functions void getStr(), vpod
recReverse(int) and void check(). The main() function to create object and call the
functions accordingly to enable the task.

Example 1:
Sample Input:
Enter a string to be reversal:
Computer Science

Sample Output:
String after reversal is :
ecneicS retupmoC
String is not Palindrome

Example 2:
Sample Input:
Enter a string to be reversal:
malayalam

Sample Output:
String after reversal is :
malayalam
String is Palindrome

34)Write a program to input a set of ‘n’ numbers (ascending order) in a single dimension
array. Enter a number and search whether the number is present among the set of
number or not by using Binary search techniques. If the number is present then display
a message “Element if found” otherwise, display “Element is not found”. Perform the
task by using Recursive technique.

Example 1:
Sample Input:
Enter the size of an array: 5
Enter array elements:
5
7
8
9
12

Enter element to be searched : 9

Sample Output:
Element is found.
Example 2:
Sample Input:
Enter the size of an array: 7
Enter array elements:
5
6
7
8
9
12
15

Enter element to be searched : 19

Sample Output:
Element is not found.

You might also like