1. Mastering Bitwise Operators in C: A Comprehensive Guide with Examples - Codzify 2. Ternary Operators in C Programming: A Beginners Guide (2023) 3. Switch Statements in C 2023: Complete Guide for Beginners 4. Learn Functions in C Programming - A Complete Tutorial for Beginners in 2023 5. Call by Value and Call by Reference in C Programming - A Complete Tutorial for Beginners in 2023 6. Storage Classes in C Programming: A Comprehensive Guide for 2023 7. Arrays in C Programming: A Comprehensive Guide for 2023 8. Basics of 2D Array in C Programming in 2023: Definition, Initialization, and Accessing Elements 9. Beginners Guide to Strings in C Programming with Codes and Examples 10. Strings Functions in C Language - strlen, strcpy,strcmp,strcat functions 11. A Comprehensive Guide to Structures in C Programming in 2023 12. Learn Unions in C Programming with Codes, Examples, and Explanations in 2023 13. Dynamic Memory Allocation in C: Understanding malloc, calloc, realloc, and free Functions 14. Introduction to C Programming 15. Hello world program in C 16. String functions in C - strncat, strcpy, strncpy, strchr, strrchr, strstr functions 17. Program for Fibonacci number in C - Codzify.com 18. What is palindrome number in C? 19. Write a C program to find a factorial of a given number 20. Write a C program to check whether a given number is prime or not 21. Write a C program to check whether a given number is an Armstrong number or not. 22. Write a C Program to transpose a matrix 23. C Programming Tutorial: Understanding Comments and Identifiers with Code Examples 24. Master String Handling Functions in C in 2023 - Codzify Topics

Write a C Program to transpose a matrix

Article by: Manish Methani

Last Updated: September 26, 2021 at 10:04am IST
1 min 21 sec

The transpose of a matrix is obtained by changing its rows into columns and its columns into rows. A rectangular array of numbers or functions that are arranged in the form of rows and columns is called a matrix.

#include <stdio.h>
#define NUMBEROFROWS      10
#define NUMBEROFCOLS      10
 
int main()
{
    int matrix[NUMBEROFROWS][NUMBEROFCOLS];
    int i,j,row,col;
    printf("Enter number of Rows :");
    scanf("%d",&row);
    printf("Enter number of Cols :");
    scanf("%d",&col);
 
    printf("Enter matrix elements :");
    for(i=0;i< row;i++)
    {
        for(j=0;j< col;j++)
        {
            printf("Enter element [%d,%d] : ",i+1,j+1);
            scanf("%d",&matrix[i][j]);
        }
    }
 
    printf("Transpose Matrix is :");
    for(i=0;i< col;i++)
    {
        for(j=0;j < row;j++)
        {
            printf("%d	",matrix[j][i]);    /*print elements*/
        }
        printf("
");   /*after each row print new line*/      
    }
    return 0;       
}

Output

    Enter number of Rows :2 
    Enter number of Cols :3 

    Enter matrix elements : 
    Enter element [1,1] : 10 
    Enter element [1,2] : 11 
    Enter element [1,3] : 12 
    Enter element [2,1] : 13 
    Enter element [2,2] : 14 
    Enter element [2,3] : 15 

    Transpose Matrix is :
    10	13	 
    11	14	 
    12	15

Learn to Build 5 Apps Without Coding using FlutterFlow

  • Lifetime access to all the 5 FlutterFlow Courses
  • Complete FlutterFlow training
  • All future course updates
  • Access via Codzify mobile app
  • 24h 42m of Learning Content
  • 5 FlutterFlow at Codzify just ₹1500 ($17.44)
  • Access to Dating App Course, Grocery App Course, Courses App Course, FlutterFlow AI Agents Course, Doctor Appointment Booking Supabase Course.
  • Clone Ready-Made Courses App instantly in FlutterFlow.
  • 30-Day 100% Money-Back Guarantee.

Learn More
Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: [email protected]