Laboratory Test II (12.03.2007)
(Section : 2)
Submission deadline : 3 p.m.
For students with odd PC numbers
1.Write a program that accepts a string from user and write a user defined function to test whether a given string is Palindrome.
Ignore blank space in string and allow one mismatch during palindrome checking. (See sample input and output)
[MARKS : 7]
Input : abb a
Output : abb a is a Palindrome
Input : a bba ab ba
Output : a bba ab ba is a Palindrome
Input : abba b
Output : abba b is not a Palindrome
Input : bbbab
Output : bbbab is a Palindrome
2. Write a
program that accept a sorted list (L) of elements and a particular element
(x) from user. Now search element x
Use the following algorithm :
x is compared with middle element in the list
if equal display the index and exit
else if x < middle element search in the lower half of the list
else search in the upper half of the list
Continue until it is found or list is empty.
[MARKS :13]
Input : Size of list (n) = 7
List of elements (L) = 21 27 17 38 45 49 73
Output : List must be sorted order
Input : Size of list (n) = 7
List of elements (L) = 21 27 48 52 59 69 71
Particular element (x) = 59
Output : Element found and its position in the list is 5
Input : Size of list (n) = 5
List of elements (L) = 14 57 60 69 74
Particular element (x) = 15
Output : Element not found
For students with even PC numbers
1. Write a
program that reads the numbers (integer or real) in a 2-dimensional
array of size n x m (n>3 & m>3). Calculate & display the row sums
and column sums , as well as grand sum in
matrix form (say, matrix1) and transform this matrix1 into a probability
matrix (where in probability matrix all entries are divided by grand sum) (see sample input and output).
Use functions to read, display, Row-sum, Column-sum and Grand-total.
[MARKS : 7]
Input : n=4 m=4
Enter numbers one by one :
3 5 8 1
4 9 6 8
2 0 3 5
7 3 4 9
Output :
Matrix1 :
3 5 8 1 17
4 9 6 8 27
2 0 3 5 10
7 3 4 9 23
16 17 21 23 77
Probability Matrix :
0.038961 0.064935 0.103896 0.012987 0.220779
0.051948 0.116883 0.077922 0.103896 0.350649
0.025974 0 0.038961 0.064935 0.129870
0.090909 0.038961 0.051948 0.116883 0.298701
0.207792 0.220779 0.272727 0.298701 1
2. Write a program that accepts (n) number of strings and output in sorted lexical order.
[MARKS : 13]
Input : n = 5
Enter strings :
Santanu Amit Dipak Maloy Bipul
Output : Lexical order of given strings :
Amit Bipul Dipak Maloy Santanu