Professional Documents
Culture Documents
JOURNAL PROGRAMS - 2021-22 - For Student
JOURNAL PROGRAMS - 2021-22 - For Student
Functions
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
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
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.
Example 1:
Sample Input: N = 192
192 x 1 = 192
192 x 2 = 384
192 x 3 = 576
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
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
Example 3:
Input: m = 50
n = 70
Example 4:
Input: m = 700
n = 450
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.
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
Specify the class Numbers giving details of the functions void getnum(), int
check(int) and void dispnum(). The main function need to be written.
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).
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.
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 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.
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
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
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
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
Sample Output:
The original matrix is:
1 2 3
4 5 6
7 8 9
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:
Example 1:
Sample Input: M = 4
N=3
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
22 5 19
7 36 12
9 13 6
Sample Output:
ORIGINAL MATRIX
22 5 19
7 36 12
9 13 6
Example 3:
Sample Input: M = 11
N=5
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)
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:
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
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:
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.
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:
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
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
Sample Output:
Element is not found.