📄 074256_3.cpp
字号:
//074256_3.cpp : To input or output a Matrix
#include"074256_1.h"
//fuction : read_matrix -----------------------------------------------------------
//To input a matrix from the keyboard
int **read_matrix(int row,int col)
{
int i=0;
int j=0;
int ok=0;
int **p_mat;
p_mat=(int **)malloc(row*sizeof(int *)); //allocate memory for Matrix
if(p_mat==NULL)
{
printf("\t\tNo enough memory!\n");
exit(1);
}
for(i=0;i<row;i++)
{
p_mat[i]=(int *)malloc(col*sizeof(int));
if(p_mat[i]==NULL)
{
printf("\t\tNo enough memory!\n");
exit(1);
}
}
printf("\tPlease input the Matrix:\n");
for(i=0;i<row;i++) //input Matrix
{
printf("\t");
for(j=0;j<col;j++)
{
ok=scanf("%d",&p_mat[i][j]);
if(!ok) //judje if the input is reasonable
{
clean();
printf("\n\t-------> Bad Data!\n");
printf("\t\tPlease input a digit ( an intager ) !\n\n\t");
break;
}
}
if(!ok)
{
printf("Please input the Matrix again:\n\t");
i=-1;
j=0;
}
}
printf("\n");
return(p_mat);
}
//fuction : print_matrix -------------------------------------------------------------------
//To print a Matrix to the screen
void print_matrix(int **p_mat,int row,int col)
{
int i=0;
int j=0;
for(i=0;i<row;i++)
{
printf("\t\t");
for(j=0;j<col;j++)
printf("%d\t",p_mat[i][j]);
printf("\n\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -