📄 hamsazeh.cpp
字号:
#include<stdio.h>
#include<conio.h>
/*
This program makes a new 3x3 matrix by removing one Row and
one Column from the original 4x4 matrix
BY: Morteza Zafari 2001.
*/
void main(){
int i,j,mat[4][4],ham[3][3];
textcolor(9);
clrscr();
printf(" ---------------------------------------------------------------");
printf("\n This program makes a new 3x3 matrix by removing one Row and");
printf("\n one Column from the original 4x4 matrix");
printf("\n BY: Morteza Zafari 2001.\n");
printf(" ---------------------------------------------------------------");
getch();
textcolor(1);
clrscr();
// Getting data from user, for a 4x4 matrix.
for(i=0;i<4;i++){
for(j=0;j<4;j++){
mat[i][j]=j+i;
printf(" Enter Row: %d, Col: %d: ",i+1,j+1);
scanf ("%d",&mat[i][j]);
}
printf("\n");
}
// Asking the user which Row and Col to delete
//printf("\n");
int r,c;
int row2del,col2del;
printf(" Which Row and Col to delete? [1-4] \n");
printf(" Row: ");
scanf ("%d",&row2del);
printf(" Col: ");
scanf ("%d",&col2del);
c=0;
r=0;
// Calculating the new 3x3 Matrix.
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if (i!=row2del-1 && j!=col2del-1){
ham[r][c]=mat[i][j];
c++;
}
}
if(i!=row2del-1 && j!=col2del-1){
r++;
c=0;
}
}
// Printing the old 4x4 Martix.
clrscr();
printf("\n\n");
for(i=0;i<4;i++){
printf("|");
for(j=0;j<4;j++){
printf(" %4d ",mat[i][j]);
}
printf("|\n");
}
printf("\n By deleting Row=%d and Col=%d of this matrix we will have: ",row2del,col2del);
printf("\n\n");
// Printing the new 3x3 Matrix.
for(i=0;i<3;i++){
printf("|");
for(j=0;j<3;j++){
printf(" %4d ",ham[i][j]);
}
printf("|\n");
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -