You are on page 1of 17

PROJECT ASSIGNMENT COMPUTER SCIENCE

CLASS XII

 WRITE ALL THE PROGRAMS ON A4 SHEET PAPER INCLUDING ALGORITHM, COMMENTS & SAMPLE I/O
ON SEPARATE PAGES WITH INDEX PAGE.
 EACH PROGRAM WILL START FROM NEW SHEET WITH QUESTION.
 FIRST PAGE OF THE PROJECT MUST BE ACKNOWLEDGEMENT.

1. WRITE AN ALGORITHM FOR THE SELECTED PROBLEM.


( Algorithm should be expressed clearly using any standard scheme such as pseudo code or in steps
which are simple enough to be obviously computable ) [10]

2. WRITE A PROGRAM IN JAVA LANGUAGE. THE PROGRAM SHOULD FOLLOW THE ALGORITHM AND
SHOULD BE LOGICALLY AND SYNTACTICALLY CORRECT. [20]

3. DOCUMENT THE PROGRAM USING MNEMONIC NAMES / COMMENTS, IDENTIFYING AND CLEARLY
DESCRIBING THE CHOICE OF DATA TYPES AND MEANING OF VARIABLES. [10]

4. CODE / TYPE THE PROGRAM ON THE COMPUTER AND GET A PRINTOUT ( HARD COPY ). TYPICALLY,
THIS SHOULD BE A PROGRAM THAT COMPILES AND RUNS CORRECTLY. [10]

5. TEST RUN THE PROGRAM ON THE COMPUTER USING THE GIVEN SAMPLE DATA AND GET A PRINTOUT OF
THE OUTPUT IN THE FORMAT SPECIFIED IN THE PROBLEM. [10]

6. VIVA-VOCE ON THE SELECTED PROBLEM. [20]

Q1) 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 an error message if the value of the day number,
year and N are not written with in the limit or not according to the condition specified.

Test your program for the random Data:


1. EXAMPLE :
INPUT   :
 :     233
DAY NUMBER
YEAR  :     2008
DATE AFTER (N)  :     17

OUTPUT   :
20TH  AUGUST  2008  
DATE  AFTER  17  DAYS  :     6TH  SEPTEMBER  2008

2. EXAMPLE :

INPUT   :
DAY NUMBER  :     360
YEAR  :     2008
DATE AFTER (N)  :     45
OUTPUT   :
25TH  DECEMBER  2008  

Page 1 of 17
DATE  AFTER  45  DAYS  :     8TH  FEBRUARY  2009
Q2) Write a program to declare a matrix A[][] of order (m * n ) where ‘m’ is the number of row and ‘n’ is the number
of column 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 ANY STANDARD
SORTING TECHNIQUE AND ARRANGE THEM IN AN ARRAY.
B) CALCULATE THE SUM OF THE OUTER ROW AND COLUMN ELEMENT.
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 :
1. EXAMPLE :
INPUT :
M=3
N=3
1 7 4
8 2 5
6 3 9
OUTPUT :
ORIGINAL MATRIX
1 7 4
8 2 5
6 3 9
REARRANGED MATRIX
1 3 4
9 2 5
8 7 6
BOUNDARY ELEMENTS
1 3 4
9 5
8 7 6
SUM OF THE OUTER ROW AND COLUMN ELEMENTS= 43

2. EXAMPLE

INPUT :
M=2
N=3
7 1 6
8 9 2
OUTPUT :

ORIGINAL MATRIX
7 1 6
8 9 2

REARRANGED MATRIX
1 2 6
9 8 7

BOUNDARY ELEMENTS
1 2 6
Page 2 of 17
9 8 7

SUM OF THE OUTER ROW AND COLUMN ELEMENTS= 33


3. EXAMPLE

INPUT :
M=4
N=4YY

REARRANGED MATRIX
1 2 4 5
23 13 8 7
15 6 3 8
12 11 9 8

BOUNDARY ELEMENTS
1 2 4 5
23 7
15 8
12 11 9 8

SUM OF THE OUTER ROW AND COLUMN ELEMENTS = 105

Q3) Read a single sentence which terminates with a full stop(.). The word 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.
INPUT : I love my country.
OUTPUT : I my love country.

Q4) Design a program which inputs a date in six digit number format i.e. 141296 . Test the validity of the date and
print the date in full form. If date is invalid then print a message as “ Invalid Date“
1. EXAMPLE:
INPUT: 141296
OUTPUT: 14th December, 96
: VALID DATE
2. Example:
INPUT: 230488
OUTPUT: 23rd April, 88
: VALID DATE
3. Example:
INPUT: 300284
OUTPUT: INVALID DATE

Q5) Accept a paragraph of text consisting of sentences that are terminated by either “.”, “,”, “!” or a “?”followed by a
space. Assume that there can be a maximum of 05 sentences in a paragraph.
Design a program to perform the following :

Page 3 of 17
(a) Arrange the sentences in alphabetical order of words, sentence by sentence.
(b) Separate the words which begin with a vowel.
Sample data 1:
INPUT: HELLO! HOW ARE YOU? WHEN ARE YOU COMING? HOPE TO SEE YOU SOON.
OUTPUT: HELLO! ARE HOW YOU? ARE COMING WHEN YOU? HOPE SEE SOON TO YOU.
VOWELS: ARE

Sample data 2:
INPUT: THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
OUTPUT: BROWN DOG FOX JUMPED LAZY OVER QUICK THE THE.
VOWELS: OVER

Q6) The computer department of the agency of International Expionage is trying to decode intercepted messages. The
agency's spies have determined that the enemy encodes messages by first converting all characters to their ASCII
values and then reversing the String.
For example :
consider A_z (the underscore is just to highlight the space). The ASCII values of A.
<space>, z are 65, 32, 122 respectively. Concatenate them to get 6532122, then reverse this to get
2212356 as the coded message.

Write a program which reads a coded message and decodes it. The coded message will not exceed 200
characters. It will contain only alphabets (A.....Z, and a....z) and spaces. ASCII values of A....Z are
65....90and those of a...z are 97....122.

Test your program for the following data and some random data.

Sample Data

Input:
Encoded Message:
2312179862310199501872379231018117927

Output:
Have A Nice Day
*************************

Input:
Encoded Message

23511011501782351112179911801562340161171141148

Output:
Truth Always Wins

Q7) A Set is a collection in which there is no duplication of elements. S = {1,6,9,24} is set of 4 integer elements. An
array of integers may be used to represent a set. You may assume that there will a maximum of 50 elements in the
set. Following are some member functions of the class set.
Input is taken by files.txt

Class Name : SetOperation

Data Members / Instance variables :

Page 4 of 17
arr[] : an array of integers to store the elements of the set

n : an integer to store the total number of elements in the set

Member functions / Methods :

set(int nn) : constructor to initialize n = nn and the array arr[]


void input() : reads the elements of the set
void display() : displays the elements of the set
set intersection(set d) : returns the intersection of set Object d and the current set Object
i.e. the set containing the elements that the common to both the sets
set union(set d) : returns the union of set Object d and the current
set Object i.e. the set containing the elements that are present in both the sets.

Specify the class set giving the details of the functions int has(int ele), set intersection(set e), set union(set
d).you may assume that the other functions / methods are written for you .

Q8) Determine minimum number of +1 and x2 operations needed to transform a into b.

Sample Input 1:
Enter the value of a
5
Enter the value of b
23

Output:
23 = ((5 * 2 + 1) * 2 + 1)

Sample Input 2:
Enter the value of a
11
Enter the value of b
113
Output:
113 = ((((11 + 1) + 1) + 1) * 2 * 2 * 2 + 1)

Q9) Gray codes. An order n Gray code is an n-bit encoding of the integers 0 to 2n - 1 such that adjacent numbers
differ in only one bit. The following is a 3-bit Gray code.
000 001 011 010 110 111 101 100
0 1 3 2 6 7 5 4

Input:
Enter the number
5

Output:
00000
00001
00011
00010
00110
00111

Page 5 of 17
00101
00100
01100
01101
01111
01110
01010
01011
01001
*/
import java.io.*;
public class GrayCode {

// append reverse of order n gray code to prefix string, and print


static void yarg(String prefix, int n) {
if (n == 0) System.out.println(prefix);
else {
gray(prefix + "1", n - 1);
yarg(prefix + "0", n - 1);
}
}

// append order n gray code to end of prefix string, and print


static void gray(String prefix, int n) {
if (n == 0) System.out.println(prefix);
else {
gray(prefix + "0", n - 1);
yarg(prefix + "1", n - 1);
}
}

public static void main(String[] args)throws IOException


{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number");
int N = Integer.parseInt(br.readLine());
gray("", N);
}

Q10) Write a program which inputs n, a natural number less than 12 and prints the natural numbers 1 to n 2 in the form
of a spiral. The spiral should move in an anti-clockwise direction, starting from row 12 and column 40 of the
screen.
Suppose n = 5 then output will be:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23 24 25
Q11) Write a program that reads in an odd integer N from the command line and prints out an N-by-N magic square.
The square contains each of the integers between 1 and N^2 exactly once, such that all row sums, column sums,
and diagonal sums are equal.

Page 6 of 17
Consider the following inputs:
Input 1:
Enter the value of N = 3

Output1:
The magic Square is as follows:
4 9 2
3 5 7
8 1 6
Input:
Enter the value of N = 5

Output2:
The magic Square is as follows:
11 18 25 2 9
10 12 19 21 3
4 6 13 20 22
23 5 7 14 16
17 24 1 8 15
Q12) Write a program that inputs the names of people into two different arrays A and B Array A has N number of
names while array B has M number of names, With no duplicates in either of them. Merge arrays A and B into a
single array C, Such that the resulting array is stored alphabetically. Test your program for the following data and
some random data.
Sample Data
Input :
Enter number of names in array A, N = 2
Enter number of names in arrayB, M = 3
First array: (A)
Suman
Anil
Second array: (B)
Usha
Sachin
John

Output:
Sorted Merged array: (C)
Anil
John
Sachin
Suman
Usha
Sorted first array: (A)
Anil
Suman
Sorted Second array:(B)
John
Sachin
Usha
Q13) Write a program to input two binary numbers in String format and perform Binary addition.
Input 1:
Enter First Binary Number

Page 7 of 17
1001
Enter Second Binary Number
1101
Output 1:
The Result is
10110
Input 2:
Enter First Binary Number
1111
Enter Second Binary Number
1111
Output 2:
The Result is
11110
Q14) A sentence in the special fashion can be printed by taking two integers (not beyond total number of words of
sentence or less than 1). These integers tell word number of the sentence. Replace only those words present at
integer places by the next character in circular fashion. If both the integers are same then replace only one word.
Let us consider the following example.
Input Sentence : He has good Books.
Input Integers : 2, 4
Output Sentence : He ibt good Cpplt.
Input Sentence : Time and tide waits for none.
Input Sentence : 3, 3
Output Sentence : Time and ujef waits for none.
Write a case sensitive program that reads a sentence from console (the characters of the sentence may be capital
or small or mixed) and two positive integers ( check otherwise ask to re-enter) and output the same sentence after
replacing each character of that word by the character which is next in the alphabetic list in circular fashion
followed by a full stop. Eg. ‘h’ will be replaced by ‘i’ , ‘a’ by ‘b’, ‘o’ by ‘p’, ‘B’ by ‘C’, ‘F’ by ‘G’, ‘z’ by ‘a’,
‘Z’ by ‘A’ etc. [ i.e. n the word no 2 ‘h’ is replaced by ‘i’ , ‘a’ by ‘b’, ‘s’ by ‘t’ and in word 4 ‘B’ by ‘C’, ‘o’ by
‘p’, ‘k’ by ‘l’, ‘s’ by ‘t’.]. Display output exactly in the above format.
Q15) Write a program to input two valid dates, each comprising of Day(2 digits),month (2 digits) and year (4 digits)
and calculate the days elapsed between the two dates. Test your program for the following data values:
(1) FIRST DATE : Day : 24
Month : 09
Year : 1960
SECOND DATE : Day : 08
Month : 12
Year : 1852

OUTPUT : XXXXXXXX
(these are actual number of days elapsed)

(2) FIRST DATE : Day : 10


Month : 01
Year : 1952
SECOND DATE : Day : 16
Month : 10
Year : 1952

OUTPUT : XXXXXXXX
(these are actual number of days elapsed)

Page 8 of 17
Q16) Write a program to input two binary numbers in String format and perform Binary substraction. (The First
binary Number Should be greater than second)
Input 1:
Enter First Binary Number
1101
Enter Second Binary Number
1001
Output 1:
The Result is
0100

Input 2:
Enter First Binary Number
1111
Enter Second Binary Number
1111
Output 2:
The Result is
0000
Q17) Write a program to input two Hexadecimal numbers in String format and perform Hexadecimal substraction.
(The First Hexadecimal Number Should be greater than second)
Input 1:
Enter First Hexadecimal Number
AAAA
Enter Second Hexadecimal Number
9999
Output 1:
The Result is
1111
Input 2:
Enter First Hexadecimal Number
FFFF
Enter Second Hexadecimal Number
AAAA
Output 2:
The Result is
5555
Q18) Write a program to enter any infix expression and evaluate it.
Sample Input:
Enter the infix expression: (a+b)/c
Enter the value of a 10
Enter the value of b 5
Enter the value of c 3

Output:
The Postfix Expression is
ab+c/
The Result is 5
Q19) Write a program to input long integer data not less than 5 digits. Your program should reject it if data is less
than 5 digits and ask to reenter. In the input last four digits will be taken as year(the validity of the year should be
checked that the year should be within 1900 to 3000, both inclusive, otherwise the computer should reject the
input and ask to reenter data) and remaining digits as total number of days . your program should display the
output as actual data.(using number of days extracted) followed by month name and actual year.

Page 9 of 17
Test your program for the following data and some random data.
Sample Input : 272008
Sample Output: 27 january 2008
Sample Input : 2008
Sample output : Invalid Data! Reenter value not less than 5 Digits.

Q20) Write a program to input a string more than of One word and Generate the following output.
Sample Input: This is my country

Sample Output:
T i m c
h s y o
i n
s t
r
y
Q21) class strarray contains an array of n characters (n<=100). You may assume that
The array contains only the letters of the English alphabet.
Some of the member functions / methods of strarray are given below.
Class name : strarray
Data Members / instance variables
Char s[]: character array
int size : the size of the array of characters
Member functions / methods
strarray() : constructor to assign to inititalize instance variables to null
strarray(char c[]) : constructor to assign character array c to the instance variable
void displayarray() : to display the list of n characters
void move() : to move all the upper case letter to the right side of the array without using any
standard sorting technique, e.g.

Input : t D f s X v d
Output : t d f s v X D
Specify the class strarray giving the details of the two constructors and the functions void displayarray() , and
void move() only. You do not need to write the main function.
Q22) A Set is a collection in which there is no duplication of elements. S = {1,6,9,24} is set of 4 integer elements.
An array of integers may be used to represent a set. You may assume that there will a maximum of 50 elements in
the
set. Following are some member functions of the class set.
Input is taken by file s.txt
Class Name : SetOperation
Data Members / Instance variables :
arr[] : an array of integers to store the elements of the set
n : an integer to store the total number of elements in the set

Member functions / Methods :


set(int nn) : constructor to initialize n = nn and the array arr[]
void input() : reads the elements of the set
void display() : displays the elements of the set
set intersection(set d) : returns the intersection of set Object d and the current set Object
i.e. the set containing the elements that the common to both the sets
set union(set d) :returns the union of set Object d and the current set Object i.e.
the set

Page 10 of 17
containing the elements that are present in both the sets.
Specify the class set giving the details of the functions int has(int ele), set intersection(set e), set union(set d).
you may assume that the other functions / methods are written for you .

Q23) The Hamming distance between two bit strings of length ‘n’ is equal to the number of bits in
Which the two strings differ .Write a program that reads in an integer ‘k’ and a bit string ‘s’ from
The command line , and prints out all bit strings that have Hamming distance at most ‘k’ from ‘s’
For Example if k is 2 and s is 0000 then your program should print out.
0011
0101
0110
1001
1100
Q24)

WAP to find all the 4 digit Vampire numbers defined as follows:

A vampire no. has an even number of digits and is formed by multiplying a pair of numbers containing half the no. of
digits of the result. The digits are taken from original no in any order . Pair of trailing zeros are not allowed. These pairs
are called the Fangs.

Example

1260 = 21 * 60

1827 = 21 * 87

2187 = 27 * 81

If no has multiple fangs display it.

Q25)
Write a program that accepts numbers, in ascending order, in an array. Search a given number using binary search
technique and display its prime factors with and without repetition. Display appropriate message if the number is not
found.

Sample Input:

Enter the range 5

Numbers

126

396

549

35100

99558

Enter Number to be searched: 35100


Page 11 of 17
Sample Output:

Prime Factors of 35100 with repetition : 2 x 2 x 3 x 3 x 3 x 5 x 5 x 13

Prime Factors of 35100 without repetition : 2 x 3 x 5 x 13

Q26) You will be given a valid expression in postfix--that is, one obtained by applying Translate to some well
bracketed expression. You have to reconstruct the original expression from the postfix expression has been obtained by
translation.

Sample input

ab+cd+e-a+-

Sample output

((a+b)-(((c+d)-e)+a))

Q27)

A Sentence is terminated by either ",",".","!","?" followed by a space.


Input a piece of text consisting of sentences.
Assume that there will be a maximum of 10 sentences in block letters.

Class name :Sentence


Data Members
String Str
Member functions
void input()
int vowel(char)
int words(String s)
void out_graph()

SCALE is 1/3
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
GRAPH
Sentence NO OF WORDS/VOWELS
1 VVVVVV
WWW

2 VVVVVVVVVVVVVVV
WWWWWWWWW

3 VVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWW

Page 12 of 17
4 VVVVVVVVV
WWWWWWWWW
Q28)
WRITE A PROGRAM TO INPUT ‘N’ INTEGERS FROM THE USER AND FIND THE LONGEST SUB-SEQUENCE OF NUMBERS IN
INCREASING / ASCENDING ORDER.
SAMPLE INPUT
9
1
2
35
14
9
20
25
30
21
SAMPLE OUTPUT:
1 2 9 20 25 30

Q29) A bank intends to design a program to display the denomination of an input amount, upto 5 digits. The available
denomination with the bank are of rupees 1000, 500, 100, 50, 20, 10, 5, 2 and 1.

Design a program to accept the amount from the user and display the break-up in descending order of denominations. (i,e
preference should be given to the highest denomination available) along with the total number of notes. [Note: only the
denomination used should be displayed].
Also print the amount in words according to the digits.
Example 1:
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000 X 14 =14000
500  X 1  =500
100  X 3  =300
50   X 1  =50
5    X 1  =5
1    X 1  =1

EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT

Q30) Encryption is a technique of coding messages to maintain their secrecy. A String array of size ‘n’ where ‘n’ is
greater than 1 and less than 10, stores single sentences (each sentence ends with a full stop) in each row of the array.
Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given
condition. Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of the odd
rows with an encryption of two characters ahead of the original character. Also change the sentence of the even rows by
storing the sentence in reverse order. Display the encrypted sentences as per the sample data given below.

Test your program on the sample data and some random data.
Input: n=4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.

Page 13 of 17
IT IS COOL.

Output:
 KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.

Input: n=13
Output: INVALID ENTRY
Q31)

Write a program to count the frequency of words length wise without using arrays considering the following assumptions:

Class name : lengthwise


Data Members
String str;//to hold text data
Member Functions
void input() //to enter the text for str
void printfrequency();//to print the frequency of words length wise
Example:
Input: India is my country
Word type Frequency
2 (word with 2 letters) 2(Total no of words)
5 (word with 5 letters) 1
7 (word with 7 letters) 1
Q32)
Write a program that accepts an odd digit N and display the structure given below.
Sample Input:
Enter a digit: 5
Output:

3
2 10 4
1 9 13 11 5
8 12 6
7

Sample Input:
Enter a digit: 7
Output:

4
3 15 5
2 14 22 16 6
1 13 21 25 23 17 7
12 20 24 18 8
11 19 9
10

Q33)
Write a program to display the structure given below for N x N matrix (N<=5).
Sample Input:
Page 14 of 17
Enter a digit: 5
Output:

7 8 9 10 11
6 1 2 12 22
5 3 13 23 21
4 14 24 25 20
15 16 17 18 19

Sample Input:
Enter a digit: 4

Output:
4 5 6 7
3 1 8 15
2 9 16 14
10 11 12 13

Q34)
Write a program to accept a date in the string format dd/mm/yyyy and accept the name of the day on 1st of January of
the corresponding year. Find the day for the given date.
Example:
Input:
Date : 5/7/2001
Day on 1st January : MONDAY
Output:
Day on 5/7/2001 : THURSDAY

Test run the program on the following inputs.

Input Date Day on 1 st January Output Day for Input Date


4/9/1998 THURSDAY FRIDAY
31/8/1999 FRIDAY TUESDAY
6/12/2000 SATURDAY WEDNESDAY

THE PROGRAM SHOULD INCLUDE THE PART FOR VALIDATING THE INPUTS NAMELY THE DATE AND THE DAY ON 1ST
JANUARY OF THAT YEAR.

Q35)
We would like to generate all possible anagrams of a word. For example if the given word is ‘TOP’, there
will be 6 possible anagrams:
TOP
TPO
OPT
OTP
PTO
POT
An anagram must be printed only once. You may output the anagrams in any order. Also output the total number of
anagrams. You may assume that the number of letters, N, in the word will be 7 at most, i.e., N<=7.
Test your program for the given data and some random data.
Sample data:
Input:
TO
Page 15 of 17
Output:
TO
OT
Total number of anagrams=2
Input :
LEAN
Output:
LEAN
LENA
LAEN
LANE
LNEA
LNAE
EALN
EANL
ELAN
ELNA
ENLA
ENAL
ALNE
ALEN
ANLE
ANEL
AENL
AELN
NLEA
NLAE
NELA
NEAL
NALE
NAEL
TOTAL NUMBER OF ANAGRAMS=24
Q36)
A sentence “IT IS NICE TO BE GOOD” in cyclic rotation can be printed as given below:
IT IS NICE TO BE GOOD
IS NICE TO BE GOOD IT
NICE TO BE GOOD IT IS
TO BE GOOD IT IS NICE
BE GOOD IT IS NICE TO
GOOD IT IS NICE TO BE
Write a program which inputs a sentence. Convert the sentence in uppercase form. Print the uppercase
sentence in cyclic rotation form. The output should be in the format as given above. Test your program with the
following sample data and some other random data.

Q37):
The consecutive prime numbers are known as Prime Triplets if they satisfy the following condition:
(n , n+2 , n+6) are all prime OR (n , n+4 , n+6) are all prime.
Where “n” is an integer number>0
Let n=5 then 5, (5+2=7), (5+6=11). Here 5, 7, 11 all are primes so (5, 7, 11) are prime triplets.
Let n=7 then 7, (7+2=9), (7+6=13). Here 7 is a prime, 9 is not a prime and 13 is primes so (7, 9, 13) are not prime
triplets.
But
Let n=7 then 7, (7+4=11), (7+6=13). Here 7 is a prime, 11 is a prime and 13 is primes so (7, 11, 13) are prime triplets.

Page 16 of 17
Few more examples of prime triplets are:
(5, 7, 11), (7, 11, 13), (11, 13, 17), (13, 17, 19), (17, 19, 23), (37, 41, 43), (41, 43, 47), (67, 71, 73), (97, 101, 103),
(101, 103, 107), (103, 107, 109), (107, 109, 113), (191, 193, 197), (193, 197, 199),……………
Write a program to input a start limit S(>0) and the last limit L(>0). Print all prime triplets between S and L
(both inclusive) if S<=L otherwise your program should ask to reenter the values of S and L again with a suitable
error message. The prime triplets may be greater or less then L depending upon the conditions used for generating
prime combinations. Print the total number of prime triplets at the end.
Check your program for the following sample data and some random data.
Sample data:
Input:
S=3
L=15
Output:
Prime Triplets
5 7 11
7 11 13
11 13 17
13 17 19
Total prime triplet combinations are =4

Input
S=9
L=45
Output:
Prime Triplets
11 13 17
13 17 19
17 19 23
37 41 43
41 43 47
Total prime triplet combinations are =5

Page 17 of 17

You might also like