Skip to main content

C Program to find transpose of a Matrix

Transpose: Transpose of a Matrix means changing Rows into Columns and vice-versa.





                                                        



Statement of C Program: This Program accepts the Matrix and prints its Transpose.


 
 
 
 
#include<stdio.h>
#include<conio.h>
void main()
{
int A[2][3] , B[3][2];
int i, j;                                   /* 'i' used for rows and 'j' used for columns */
clrscr();
printf(" Enter the elements of A\n");
for(i=0 ; i<2 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf("%d" , &A[i][j] );
}
}

printf(" Matrix is\n");
for(i=0 ; i<2 ; i++)
{
for(j=0 ; j<3 ; j++)
{
printf("%d\t" , A[i][j] );                            /* '\t' used for Tab */ 
}                                                          
printf("\n");                                       /* '\n' used for next line character */
}


for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<2 ; j++)
{
B[i][j] = A[j][i];
}
}

printf(" After Transpose\n");
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<2 ; j++)
{
printf("%d\t" , B[i][j] );                            
}                                                          
printf("\n");                                      
}

getch();
}                                                       /* End of main */
 

 Output:

 


 
 

Comments

Popular posts from this blog

To Check Whether a Number is Even or Odd

C Program to Check Whether a Number is Even or Odd Numbers perfectly divisible by 2 are known even numbers and numbers which are not divisible by 2 are called odd numbers. This program takes an integer from user and checks whether that number is even or odd and displays the result. Source Code /*to check whether a number entered by user is even or odd. */ #include <stdio.h> int main() { int num; printf( "Enter an integer you want to check: " ); scanf( "%d" ,&num); if ((num% 2 )== 0 ) /* Checking whether remainder is 0 or not. */ printf( "%d is even." ,num); else printf( "%d is odd." ,num); return 0 ; } Output 1 Enter an integer you want to check : 25 25 is odd . Output 2 Enter an integer you want to check : 12 12 is even .   In this program, user is asked to enter an integer which is stored in variable num . Then,...

Sum, Average and Standard deviation in c

 Sum, Average and Standard deviation Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ). #include <stdio.h> void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std) void main() { clrscr(); float ave,sd; int a,b,c,d,e,sum; printf( "\nInput 5 integers\n" ); scanf( "\n%d\n%d\n%d\n%d\n%d" ,&a,&b,&c,&d,&e);   stat(a,b,c,d,e,&sum,&ave,&sd); printf( "\nThe sum is %d\nThe average is %f\nThe standard deviation is %f" ,sum,ave,sd); } void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std) { * su=a+b+c+d+e; * av= * su/5; * std=sqrt(((((a-*av)*(a-*av))+((b-*av)*(b-*av))+((c-*av)*(c-*av)))/5.0); }

Convert numbers to roman numerals

Convert numbers to roman numerals       #include <stdio.h> #include <conio.h> void predigits (char c1,char c2); void postdigits (char c,int n); char roman_Number[1000]; int i=0; int main() {     int j;     long int number;        printf( "Enter any natural number: " );     scanf( "%d" ,&number);        if (number <= 0) {          printf("Invalid number");          return 0;     }     while (number != 0){          if (number >= 1000){              postdigits('M',number/1000);              number = number - (number/1000) * 1000;          } ...