C Program to find sum of two numbers



#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],t[3][3],i,j,m,n;
clrscr();
printf("\nEnter number of rows and column of a matrix:");
scanf("%d%d",&m,&n);
printf("\nEnter elements in matrix:");
for(i=0;i {
for(j=0;j {
printf("\na[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i {
for(j=0;j {
t[j][i]=a[i][j];
}
}
printf("Transpose of given matrix is:");
for(i=0;i {
for(j=0;j {
printf("\na[%d][%d]=",i,j);
printf("%d",t[i][j]);
}
}
getch();
}

Explanation:

The above program will calculate the transpose of a matrix of 2*2 order. We can understand its process by following example:

m=2,n=2
a[0][0]=1,a[0][1]=2,a[1][0]=3,a[1][1]=4
i=0
i iteration1 (Outer loop)
j=0
j iteration1 (Inner loop)
t[j][i]=a[i][j] so,
t[0][0]=a[0][0]=1
Increment j by 1 now j=1
j iteration 2 (Inner loop)
t[1][0]=a[0][1]=2
Increment j by 1 now j=2
j Increment i by 1 now i=1
i iteration 2 (Outer loop)
j=0
j iteration 1 (Inner loop)
t[j][i]=a[i][j]
so t[0][1]=a[1][0]=3
Increment j by 1 now j=1
j iteration 2 (Inner loop)
t[1][1]=a[1][1]=4
Increment j by 1 now j=2
j Increment i by 1 now i=2
i loop break..
So we get the following output after the multiplication of given matrices:

Output:

c program