Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

Transpose of Matrix in C

Transpose of a Matrix in C

✅ Transpose of a Matrix in C

#include <stdio.h>

int main() {
    int row, col;

    printf("Enter number of rows and columns:\n");
    scanf("%d %d", &row, &col);

    int matrix[row][col], transpose[col][row];

    printf("Enter %d elements in the matrix:\n", row * col);
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }

    // Print Original Matrix
    printf("\nOriginal Matrix:\n");
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }

    // Transpose the matrix
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            transpose[j][i] = matrix[i][j];
        }
    }

    // Print Transposed Matrix
    printf("\nTransposed Matrix:\n");
    for(int i = 0; i < col; i++) {
        for(int j = 0; j < row; j++) {
            printf("%d ", transpose[i][j]);
        }
        printf("\n");
    }

    return 0;
}
  

πŸ“˜ Explanation:

In this program, we read a 2D matrix from the user and then print its transpose. A transpose of a matrix is formed by interchanging its rows and columns. For example, if element matrix[i][j] is at row i and column j, then it is placed at transpose[j][i] in the transposed matrix.

This method is useful in applications like image processing, solving systems of linear equations, and matrix algebra.

The user first inputs the number of rows and columns. The program then takes all matrix values, prints the original matrix, computes its transpose, and prints the result.

🧾 Sample Output:

Enter number of rows and columns:
2 3
Enter 6 elements in the matrix:
1 2 3
4 5 6

Original Matrix:
1 2 3
4 5 6

Transposed Matrix:
1 4
2 5
3 6
  

πŸ”‘ Keywords:

Transpose of Matrix in C, Matrix Transpose C Program, C language 2D Arrays, Matrix Programs in C, C Program with Input and Output, Matrix Logic in C, Transpose Algorithm in C, C Coding Examples, Beginner C Programs

πŸ“Œ Hashtags:

#CProgramming #MatrixTranspose #CPrograms #2DArrays #TransposeInC #CodingInC #BeginnerFriendly #CLanguage

Comments

Popular Posts

πŸŒ™