
C Program to implement modulo (%) operator using bitwise operators
September 07, 2025
1 min

This is essentially asking for a transpose of a square matrix (rows become columns and vice versa). Below is a simple program to implement this problem,
#include <stdio.h>#define MAX 10 // maximum size of the matrix// Function to print the matrixvoid printMatrix(int matrix[MAX][MAX], int n) {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {printf("%d\t", matrix[i][j]);}printf("\n");}}int main() {int n;int matrix[MAX][MAX];printf("Enter the size of the square matrix (n x n): ");scanf("%d", &n);if (n > MAX) {printf("Error: Maximum size allowed is %d\n", MAX);return 1;}printf("Enter the elements of the %d x %d matrix:\n", n, n);for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {scanf("%d", &matrix[i][j]);}}printf("\nOriginal Matrix:\n");printMatrix(matrix, n);// Transpose in place (swap rows and columns)for (int i = 0; i < n; i++) {for (int j = i + 1; j < n; j++) {int temp = matrix[i][j];matrix[i][j] = matrix[j][i];matrix[j][i] = temp;}}printf("\nMatrix after swapping rows to columns (Transpose):\n");printMatrix(matrix, n);return 0;}






Quick Links
Legal Stuff