A blog posting problems and tutorials for blog visitors to practice and gain experience.
AD1
Saturday, 23 September 2017
Monday, 18 September 2017
Matrix Transpose
Given a 2D array A, your task is to convert all rows to columns and columns to rows.
Input:
First line contains 2 space separated integers, N - total rows, M - total columns.
Each of the next N lines will contain M space separated integers.
Output:
Print M lines each containing N space separated integers.
Constraints:
1≤N≤10
1≤M≤10
0≤A[i][j]≤100 where 1≤i≤N and 1≤j≤M
Solution
Input:
First line contains 2 space separated integers, N - total rows, M - total columns.
Each of the next N lines will contain M space separated integers.
Output:
Print M lines each containing N space separated integers.
Constraints:
1≤N≤10
1≤M≤10
0≤A[i][j]≤100 where 1≤i≤N and 1≤j≤M
Solution
Saturday, 16 September 2017
Count frequency of each element in array
Write a program to count the frequency of each element in array , as example if we have
int a[10]={5, 10, 2, 5, 50, 5, 10, 1, 2, 2};
the output should be
number frequency
5 3
10 2
2 3
50 1
1 1
int a[10]={5, 10, 2, 5, 50, 5, 10, 1, 2, 2};
the output should be
number frequency
5 3
10 2
2 3
50 1
1 1
Subscribe to:
Posts (Atom)