This program determines Transpose of a Matrix in C
Program Code:
//to find determine Transpose of a Matrix.
#include <stdio.h>
#include <stdlib.h>
//Function to print matrix
void print(int matrix[][10], int row, int col)
{
int idx, jdx;
printf("\n Answer:\n");
for (idx = 0; idx < row; idx++)
{
for (jdx = 0; jdx < col; jdx++)
{
printf(" %d ", matrix[idx][jdx]);
}
printf("\n");
}
}
//function to transpose
int transpose(int matrix[][10], int row, int col)
{
int ans_matrix[10][10], idx, jdx;
for (idx = 0; idx < row; idx++)
{
for (jdx = 0; jdx < col; jdx++)
{
ans_matrix[jdx][idx] = matrix[idx][jdx];
}
}
print(ans_matrix, col, row);
return 0;
}
int main()
{
//declaring variables
int matrix[10][10], row, col, idx, jdx, Det;
char ch;
do
{
//reading an action from the user and the order of the matrix
printf(" =================================");
printf(" \n Transpose of Matrix \n");
printf(" =================================\n");
printf(" Enter the Size for Matrix\n Row's = ");
scanf("%d", &row);
printf(" Col's = ");
scanf("%d", &col);
//reading the matrix
for (idx = 0; idx < row; idx++)
{
printf(" Enter %d numbers for Row %d : ", col, idx + 1);
for (jdx = 0; jdx < col; jdx++)
{
scanf("%d", &matrix[idx][jdx]);
}
}
transpose(matrix, row, col);
printf("\n To Continue press [Y/n] : ");
getchar();
} while ((ch = getchar()) && (ch == 'y' || ch == 'Y'));
return 0;
}
Program Output:
Post a Comment