Hot Topics

D.E Shaw Solutions
Technical Round
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int result = (1 << n) - 1;
printf("%d\n", result);
return 0;
}
In this code, n
is the input number from the interval [0, 32]. The 1 << n
expression will shift the value of 1 to the left by n
bits, and the - 1
will set the n
least-significant bits to 1, while other bits will be set to 0. The result is then printed to the standard output.
void transpose(int rows, int cols, int matrix[rows][cols]) {
for (int i = 0; i < rows; i++) {
for (int j = i + 1; j < cols; j++) {
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
}
This code uses a nested for loop to transpose the matrix. The outer loop i
iterates through each row, and the inner loop j
iterates through each column. For each iteration, the elements at matrix[i][j]
and matrix[j][i]
are swapped. This ensures that the elements on the main diagonal remain unchanged and the rest of the elements are transposed.
It’s important to note that this code only works for square matrices (i.e., matrices with an equal number of rows and columns). For non-square matrices, you would need to modify the code to handle the different dimensions.




Popular Category
Hot Topics
Go through our study material. Your Job is awaiting.