Write a function to transpose a NxN matrix. Do it in-place. e.g. m={{1,2,3},{4,5,6},{7,8,9}} ==> m={1,4,7},{2,5,8}{3,6,9}}. Function prototype is like this "transpose(dimension, pointer to 2-d array)".
Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. Examples: 1 / \ 2 3 / \ / \ 4 5 6 7 The tree has 5 vertical lines Vertical-Line-1 has only one node 4 => vertical sum is 4 Vertical-Line-2: has only one node 2=> vertical sum is 2 Vertical-Line-3: has three nodes: 1,5,6 => vertical sum is 1+5+6 = 12 Vertical-Line-4: has only one node 3 => vertical sum is 3 Vertical-Line-5: has only one node 7 => vertical sum is 7 So expected output is 4, 2, 12, 3 and 7
#include
ReplyDeleteint main(int argc, char *argv[])
{
int a[4][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13, 14, 15, 16}};
int i, j, temp;
int dim = 4;
for (i=0; i<dim-1; i++)
{
for (j=i; j<dim; j++)
{
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
for (i=0; i<dim; i++)
{
for (j=0; j<dim; j++)
{
printf("%d", a[i][j]);
}
printf("\n");
}
return 0;
}