Download as DOC, PDF, TXT or read online from Scribd
Download as doc, pdf, or txt
You are on page 1/ 3
ISC Practical 2002 – KP, Page 1 of 4
COMPUTER SCIENCE – 2002
Paper-2 (PRACTICAL) (Planning Session : Two hours) (Examination Session: one hour) (Maximum Marks: 100) --------------------------------------… INSTRUCTIONS As it is a practical examination, the candidate is expected to do the following: (a) Write an algorithm for the selected problem. (b) Prepare an Input/Process/Output table indicating the required inputs for the problem. Also state the method/formula for solving the problem and mention the required output. (c) Write a program in C++, test run the program on the computer using the given test data and get a print out (hard copy) in the format specified in the problem alongwith the program listing. Solve any one of the following problems Q1. Twins primes are consecutive prime numbers whose difference is 2. For example, (3,5), (11,13), (17,19) are all twin primes. We define the distance of any twin prime pair from a positive integer as follows. If (p1, p2) is a twin prime pair and n is a positive integer then the distance of the twin prime from n is: minimum(abs(n-p1), abs(n-p2)) where abs returns the absolute value of its argument, and minimum returns the smaller of its two arguments. Write a program that reads in a positive integer n and prints out the twin prime pair that has the least distance from n.
ISC Practical 2002 – KP, Page 2 of 4
For example if n is 30 the pair is (29,31), if n is 13 it is (11,13), if n is 49 it is (41,43). If n is 54 it is (59,61). Sample data: Input: Give the number : 34 Output: Number read in is : 34 Pl=29 p2=31 Input: Give the number : 60 Output: Number read in is 60 Pl=59 p2=61 Q2. Write the program to do the following: Read in an integer n (which can be at most 50). Then read in n integers one by one and store them in an array data from index 0 to n-1. Now we want to rearrange the integers in data in the following way : Find the maximum value in data and put in the centre of the array (that is at (n/2); find the next largest value and put it to its right; then the next largest and place it to its left and so on alternating right and left until all integers in data are done. For example, if the array is initially: 7, 3, 1, 6, 4, 2, 5 then after rearranging it becomes 1, 3, 5, 7, 6, 4, 2 However, since we have very little memory, you are not allowed to use any other array from data. Sample data: Input:
ISC Practical 2002 – KP, Page 3 of 4
Give the number of integers: 5 Give integer 1 : 7 Give integer 2 : 9 Give integer 3 : 2 Give integer 4 : 5 Give integer 5 : 6 Output: Original array 79256 rearranged array 26975 Input: Give the number of integers: 6 Give integer 1 : 5 Give integer 2 : 1 Give integer 3 : 9 Give integer 4 : 8 Give integer 5 : 2 Give integer 6 : 4 ] Output: Original array 519824 rearranged array 259841 Q3. A mathematician who is working with extremely large integers represents them using a doubly linked list. For example, the number 7328 will be represented as the doubly linked list with four nodes:
ISC Practical 2002 – KP, Page 4 of 4
The predecessors of the first node and the successor of the last node are null. Write a program that reads in two numbers (assume they are integers for testing), converts them to the above representation, prints them out with each digit separated by commas and checks should work on the representation and not on the integers,. Here are sample outputs. Sample data: Input: Give the first number : 34563 Give the second number: 34562 Output: First number : 3,4,5,6,3 Second number: 3,4,5,6,2 unequal Input: Give the first number : 56432 Give the second number: 56432 Output: First number : 5,6,4,3,2 Second number : 5,6,4,3,2 equal *** 7328