Problem Sheet 4

This problem sheet was created by Sir Narasimhan T, Assistant Professor, IT Department LBS College of Engineering, Kasaragod

The softcopy in .pdf is available here. There is  a bit more in the file.

1)Write a program to reverse the contents of an 1D array without using a second array.

2)Assume that an integer array contains duplicate entries. Find the mode of this array. Mode is that element that occurs the most number of times. A sample input and output is shown below:
Enter array size
Enter 7 elements
2  1  -1  2  -1  4  -1
The mode is  -1

3)Rotate an array r times. Print the array after each rotation. A sample input and output is shown below.
Enter the array size
Enter the elements
10 7 8 25 16
How many times you want to rotate?
Array after rotation 1
16 10 7 8 25
Array after rotation 2
25 16 10 7 8
Array after rotation 3
8 25 16 10 7

4)An election is contested by 5 candidates whose symbols are @, #, $, % and &. The voting is done by marking the candidate symbol on the ballot paper. Get the number of voters from the user, conduct the election and announce the result. If a ballot is marked with a symbol other than those given above, it is considered as spoilt ballot. Spoilt ballots should not be considered during the counting process.

5)You are given the task of evaluating a test of 10 questions each of multiple-choice type. There are 4 possible choices A, B, C and D of which only one is correct. The answers are stored in a string ANSWER such that ith character in the string is the answer of (i+1)th question, 0 ≤ i ≤ 9. Say, if the first 5 questions have answers A and all others have B, then ANSWER is AAAAABBBBB. The student takes the test and submits his answer as a 10 character string TEST. If he doesn’t know the answer, he gives ’X’ for the corresponding question. For example, if the student gives ’A’ for 2nd and 7th questions, 4th question, a ’C’, doesn’t know the answer for 10th question and gives all other questions, a ’D’, his answer string TEST will be DADCDDADDX. Get the number of students from the user and get the answer string of each student and display the marks scored by each student. Assume that each correct answer carries 1 mark and wrong answer has a penalty of 0.25 mark.(negative mark)

6)Insert an element at a given position in the array. Sample input and output is given below:
Enter array size
Enter array elements
5  4  8  100  1024  4015  7
Enter the position and element to insert
3  45
The array after insertion of 45 is
5  4  8  45  100  1024  4015  7

7)Delete an element from a given position in the array. Sample input and output is given below:
Enter array size
Enter array elements
7 2 108 10 24 15
Enter the position to delete
The element deleted is 24 and the array after deletion is
7 2 108 10 15

8)Assume an array has duplicate entries. Remove the duplicate entries from this array. After the removal of all duplicate entries, the remaining elements should be in continuous positions.
Sample input and output is shown below:
Enter array size
Enter array elements
1 45 2 1 7 45 28 1 7
The array after removing duplicates is
1 45 2 7 28


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s