C语言求行列式的值
按如下公式递归计算矩阵行列式的值:(如图)**输入格式要求:"%d""%lf"提示信息:"Pleaseentermatrixsizen(1<=n<20):""Please...
按如下公式递归计算矩阵行列式的值:(如图
)
**输入格式要求:"%d" "%lf"
提示信息:"Please enter matrix size n(1<=n<20):" "Please input matrix line by line:\n" "matrix a:\n"**输出格式要求:"Submatrix:\n" "DValue of the Submatrix is %6.1f\n" "%6.1f\t" "result = %f\n"
程序运行结果如下:
Please enter matrix size n(1<=n<20):3< span="">Please input matrix line by line:
1 2 34 5 78 9 11matrix a: 1.0 2.0 3.0 4.0 5.0 7.0 8.0 9.0 11.0
Submatrix: 5.0 7.0 9.0 11.0DValue of the Submatrix is -8.0Submatrix: 4.0 7.0 8.0 11.0DValue of the Submatrix is -12.0Submatrix: 4.0 5.0 8.0 9.0DValue of the Submatrix is -4.0result = 4.000000
表达格式要符合题目示例哦 展开
)
**输入格式要求:"%d" "%lf"
提示信息:"Please enter matrix size n(1<=n<20):" "Please input matrix line by line:\n" "matrix a:\n"**输出格式要求:"Submatrix:\n" "DValue of the Submatrix is %6.1f\n" "%6.1f\t" "result = %f\n"
程序运行结果如下:
Please enter matrix size n(1<=n<20):3< span="">Please input matrix line by line:
1 2 34 5 78 9 11matrix a: 1.0 2.0 3.0 4.0 5.0 7.0 8.0 9.0 11.0
Submatrix: 5.0 7.0 9.0 11.0DValue of the Submatrix is -8.0Submatrix: 4.0 7.0 8.0 11.0DValue of the Submatrix is -12.0Submatrix: 4.0 5.0 8.0 9.0DValue of the Submatrix is -4.0result = 4.000000
表达格式要符合题目示例哦 展开
2个回答
展开全部
C语言程序如下:
#include <stdio.h>
#include <math.h>
#define MAX 100
double D(double arr[][MAX], int n);
void Display(double arr[][MAX], int n);
void main()
{
double arr[MAX][MAX];
double bak[MAX][MAX];
double value;
int n;
int i, j, k, c;
printf("Please enter matrix size n(1<=n<20):");
scanf("%d", &n);
printf("Please input matrix line by line:\n");
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
scanf("%lf", &arr[i][j]);
}
}
printf("matrix a:\n");
Display(arr, n);
/* 保存D(0,i)的值到bak中 */
for(i=0; i<n; i++) /* 处理第1行的每一列元素 */
{
for(j=1; j<n; j++) /* 逐行处理 */
{
for(c=0,k=0; k<n; k++) /* 逐列处理 */
{
if(k == i)
{
continue;
}
bak[j-1][c++] = arr[j][k];
}
}
value = D(bak, n-1);
printf("Submatrix:\n");
Display(bak, n-1);
printf("DValue of the Submatrix is %f\n", D(bak, n-1));
}
value = D(arr, n);
printf("result = %f\n", value);
}
double D(double arr[][MAX], int n)
{
double bak[MAX][MAX];
int i, j, k, c, d;
double sum = 0;
if(n == 1)
{
return arr[0][0];
}
for(i=0; i<n; i++) /* 处理第1行的每一列元素 */
{
for(j=1; j<n; j++) /* 逐行处理 */
{
for(c=0,k=0; k<n; k++) /* 逐列处理 */
{
if(k == i)
{
continue;
}
bak[j-1][c++] = arr[j][k];
}
}
/* 计算arr(row, col) * D(row, col)的值 */
sum += (i % 2 == 0 ? 1 : -1) * arr[0][i] * D(bak, n-1);
}
return sum;
}
void Display(double arr[][MAX], int n)
{
int i, j;
printf("");
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
printf("%10.1lf", arr[i][j]);
}
printf("\n");
}
}
运行测试:
2016-05-08
展开全部
我可以有偿代劳
追问
多少
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询