#include <stdio.h>
#include <conio.h>
void main()
{
int mainMat[10][10], minorMat[10][10], i, j, x, y, r, c;
clrscr();
printf("This program can find a minor matrix based on any element of a given matrix. \n");
printf("Please enter the number of rows and columns of the main matrix\n"); scanf("%d%d", &r, &c);
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{
mainMat[i][j] = 0;
}
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{
minorMat[i][j] = 0;
}
printf("Now enter the following elements for the matrix: \n");
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{
printf("Enter the element a%d%d: ", i+1, j+1);
scanf("%d", &mainMat[i][j]);
}
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{
mainMat[i][j] = minorMat[i][j];
}
printf("\nNow enter the coordinates of the element in the matrix you want to base the minor matrix upon: ");
scanf("%d%d", &x ,&y);
for(i=x; i<r; i++)
for(j=0; j<c; j++)
{
minorMat[i-1][j] = minorMat[i][j];
}
for(i=0; i<r; i++)
for(j=y; j<c; j++)
{
minorMat[i][j-1] = minorMat[i][j];
}
printf("\nOutput Matrix:\n\n");
for(i=0; i<r-1; i++)
for(j=0; j<c-1; j++)
{
printf("%d ", minorMat[i][j]);
if(j==c-2)
printf("\n\n");
}
getch();
}
Follow these steps:
Once you have done all this come back with your findings.
#include <stdio.h> #include <conio.h> void main() { int mainMat[10][10], minorMat[10][10], i, j, x, y, r, c, num1=0,num2=0; clrscr(); printf("This program can find a minor matrix based on any element of a given matrix. \n"); printf("Please enter the number of rows and columns of the main matrix\n"); scanf("%d%d", &r, &c); for(i=0; i<r; i++) for(j=0; j<c; j++) { mainMat[i][j] = 0; } for(i=0; i<r; i++) for(j=0; j<c; j++) { minorMat[i][j] = 0; } printf("Now enter the following elements for the matrix: \n"); for(i=0; i<r; i++) for(j=0; j<c; j++) { printf("Enter the element a%d%d: ", i+1, j+1); scanf("%d", &mainMat[i][j]); } // for(i=0; i<r; i++) // for(j=0; j<c; j++) // { // printf("mainMat[%d][%d] = [%d]",i,j,mainMat[i][j]); // printf("\n"); // } printf("\nNow enter the coordinates of the element in the matrix you want to base the minor matrix upon: "); scanf("%d%d", &x ,&y); printf("x=%d,y=%d",x,y); for(i=0; i<r; i++) { num2=0; if(i == x-1) { printf("i=%d, x-1=%d",i,x-1); continue; } for(j=0; j<c; j++) { if (j == y-1) { continue; } else { minorMat[num1][num2] = mainMat[i][j]; num2++; } } num1++; } printf("num1=%d, num2= %d",num1,num2); printf("\nOutput Matrix:\n\n"); for(i=0; i<num1; i++){ for(j=0; j<num2; j++) { printf("minorMat[%d][%d] = %d ",i,j,minorMat[i][j]); printf("\n\n"); } } getch(); }