ESc101 Laboratory Assignment
Tuesday of Week of 20/09/04
The Assignment consists of THREE programs. USE OF ARRAYS IS NOT ALLOWED.
1) You are given a string, print its reverse string.
2) Given a string of, print all its permutations. You may print all n-factorial
permutations even if some are identical (due to multiple occurance of the
same character in the input string. Use objects of StringBuffer Class. (String
Class represents fixed-length, immutable character sequences. In contrast,
StringBuffer Class represents growable and writable character sequences.)
The hint given below is for strings of length 5. Write a program which would
work for a string of any length.
HINT: Suppose the length of string is 5, then the total number of permutations
possible is 5!(=120). Now, generate 4 tuples as follows:
For each i from 0 to 119, construct a 4-tuple as follows:
j = i
a = j/4!
j = j % 4!
b = j/3!
j = j % 3!
c = j/2!
j = j % 2!
d = j/1!
For example the 4-tuple for 0 will be <0,0,0,0> and that for 68 is <2,3,1,0>.
Now construct a permutation from a given 4-tuple as follows.
For the input string of length 5, extract the character at position a and
insert 'nul' (ASCII 0) there. Next extract b-th non-nul character and insert
nul there. Next extract c-th non-nul character and insert nul there, and so on.
After extracting 4 characters finally extract the last non-nul character. Print
these character as a string in that order.
3) Write a program that generates Pascal's table for n rows, n given by
the user.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 1