Arrays / Hands On Session X (part-3)

9. Compare 2 arrays

Write a program to find whether 2 arrays are the same.
Input Format:
Input consists of 2n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. The next ‘n’ integers correspond to the elements in the second array.Assume that the maximum value of n is 15.
Output Format:
Print yes if the 2 arrays are the same. Print no if the 2 arrays are different.
Sample Input 1:
5
2
3
6
8
-1
2
3
6
8
-1
Sample Output 1:
yes

code:



10.Functions – Array Maximum


Write a program to find the maximum element in the array using functions.

Function specification:

int findMax(int n, int *a)
The first argument corresponds to the number of elements in the array.
The second argument corresponds to the pointer to an array.

Input and Output Format:

Input consists of n+1 integers where n corresponds to the number of elements in the array.
The first integer corresponds to n and the next n integers correspond to the elements in the array.

Output consists of a single integer which corresponds to the maximum element in an array.
Assume that the maximum number of elements in the array is 20.

Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output :

Enter the number of elements in the array
5
Enter the elements in the array
2
4
1
3
5
The maximum element in the array is 5



Function Definitions: 
int findMax (int n, int *a) 
code:



11.Functions – Matrix Maximum


Write a program to find the maximum element in a matrix using functions.

Function specification:

int findMax(int **a, int m, int n)
The first argument corresponds to the pointer to the matrix.
The second argument corresponds to the number of rows in the matrix.
The third argument corresponds to the number of columns in the matrix.


Input and Output Format:

Assume that the maximum number of rows and columns in the matrix is 10.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output :

Enter the number of rows in the matrix
3
Enter the number of columns in the matrix
2
Enter the elements of the matrix
2
4
1
3
5
9
The matrix is
2 4
1 3
5 9
The maximum element in the matrix is 9



Function Definitions: 
int findMax (int **a, int m, int n) 

code:





12.Functions – Null Matrix



Write a program to find whether the given matrix is null or not using functions.
A null matrix is a matrix in which all its elements are zero.

Function specification:

int checkNull(int **a, int m, int n)
The first argument corresponds to the pointer to an array.
The second argument corresponds to the number of rows.
The third argument corresponds to the number of columns.
The function returns a value of 1 if it is a null matrix and 0 otherwise.

Input and Output Format:

Assume that the maximum number of rows and columns in the matrix is 10.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:

Enter the number of rows in the matrix
3
Enter the number of columns in the matrix
2
Enter the elements of the matrix
2
4
1
3
0
9
The matrix is
2 4
1 3
0 9
The matrix is not null

Sample Input and Output 2:

Enter the number of rows in the matrix
2
Enter the number of columns in the matrix
2
Enter the elements of the matrix
0
0
0
0
The matrix is
0 0
0 0
The matrix is null


Function Definitions: 

int checkNull (int **a, int m, int n) 
code:



Thankyou ... 

1 comment: