Page 336 - Computer science 868 Class 12
P. 336
for(int k=0;k<a.length;k++)
System.out.println(a[k]);
}
(i) What is the expression or statement at ?1? (ii) What is the expression or statement at ?2?
(iii) What is the expression or statement at ?3? (iv) What is the expression or statement at ?4?
(v) What is the expression or statement at ?5?
D. Programs related to Arrays:
1. Write a program to input “n” number of elements in an array[] and print the frequency of each number in the array.
2. Write a program to input 20 numbers in an array and print the sum of all the given numbers in the array.
3. Write a program to accept a set of n integers (where n > 0) in a single-dimensional array. Arrange the elements of the array such
that the lowest number appears in the centre of the array, the next lower number in the right cell of the centre, the next lower
in the left cell of the centre and so on. The process will stop when the highest number will be set in its appropriate cell. Finally,
display the array elements.
Assume that the memory space is less. Hence, you don't need to create an extra array for the aforesaid task.
Example:
Input: 1 2 3 4 5
Output: 5 3 1 2 4
Input: 11 12 31 14 5
Output: 31 12 5 11 14
4. A company manufactures packing cartons in four sizes, i.e., cartons to accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes.
Design a program to accept the number of boxes to be packed (N) by the user (maximum up to 1000 boxes) and display the break-
up of the cartons used in descending order of capacity (i.e., preference should be given to the highest capacity available, and if
boxes left are less than 6, an extra carton of capacity 6 should be used.)
Test your program with the following data and some random data:
INPUT:
N = 726
OUTPUT:
48 * 15 = 720
6 * 1 = 6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
5. Given a square matrix M[][] of order 'n'. The maximum value possible for 'n' is 10. Accept three different characters from the
keyboard and fill the array according to the output shown in the examples given below. If the value of n exceeds 10 then an
appropriate message should be displayed.
Enter Size: 4
Input:
First Character '*'
Second Character '?'
Third Character '#'
Output:
# * * #
? # # ?
? # # ?
# * * #
6. Two matrices are said to be equal if they have the same dimension and their corresponding elements are equal.
For example, the two matrices A and B given below are equal:
Matrix A Matrix B
1 2 3 1 2 3
2 4 5 2 4 5
3 5 6 3 5 6
Design a class EqMat to check if the matrices are equal or not. Assume that the two matrices have the same dimension.
Class name : EqMat
Data Members
a[][] : to store integer elements
334334 Touchpad Computer Science-XII

