用C解线性方程组.请.还没有完工,呵 呵
用C解线性方程组.请高手指点.还没有完工,呵 呵
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define LEN sizeof(struct matrix)
//链表结构
struct matrix
{
float arr;
struct matrix * next;
}
//主函数
main()
{
//函数声明
struct matrix * matrix_det(int row, int col);//输入行列式的系数
struct matrix * print(struct matrix * head, int rows, int cols);//输出行列式的系数
struct matrix * matrix_sort(struct matrix * head, int rows, int cols);//排序行列式
struct matrix * matrix_ones(int col);//建立一个空的链表
int rows,cols; //定义行和列的变量
struct matrix * tpr;
printf( "请输入行列式的系数:\n ");
printf( "请输入行数: ");scanf( "%d ",&rows);
printf( "请输入列数: ");scanf( "%d ",&cols);
tpr = matrix_det(rows,cols);
print(tpr,rows,cols);
save_det(tpr,rows,cols);
tpr = matrix_sort(tpr,rows,cols);
printf( "\n排序后: ");
print(tpr,rows,cols);
save_det(tpr,rows,cols);
getch();
}
//用链表动态输入系数行列式
struct matrix * matrix_det(int row, int col)
{
int i,j,ji;
struct matrix * head,*prf,*prb;
head = prf = prb = (struct matrix *)malloc(LEN);
ji=row*col;
for(i=0;i <row;i++)
{
printf( "第%d行: ",i+1);
for(j=0;j <col;j++)
{
scanf( "%f ",&prf-> arr);
prf = (struct matrix *)malloc(LEN);
prb-> next = prf;
prb = prf;
}
prb-> next = NULL;
}
return (head);
}
//创建一个空链表
struct matrix * matrix_ones(int col)
{
int i;
struct matrix *head, *prf, *prb;
head = prf = prb = (struct matrix *)malloc(LEN);
for(i=0;i <col;i++)
{
prf-> arr = 1;
prf = (struct matrix *)malloc(LEN);
prb-> next = prf;
prb = prf;
}
prb-> next = NULL;
return (head);
}
//输出系数
struct matrix * print(struct matrix * head, int row, int col)
{
int i,j;
struct matrix * tpr;
tpr = head;
printf( "\n行列式:\n------\n ");
for(i=0;i <row;i++)
{
for(j=0;j <col;j++)
{
printf( "%12.2f\t ",tpr-> arr);
tpr = tpr-> next;
}
printf( "\n "); //输出换行
}
printf( "------\n ");
return 0;
}
//对行列式进行排序:冒泡法
struct matrix * matrix_sort(struct matrix * head, int row, int col)
{
int ir, ic, it,i;
float tf;
struct matrix * pf, * pb,*pf1,*pb1;
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define LEN sizeof(struct matrix)
//链表结构
struct matrix
{
float arr;
struct matrix * next;
}
//主函数
main()
{
//函数声明
struct matrix * matrix_det(int row, int col);//输入行列式的系数
struct matrix * print(struct matrix * head, int rows, int cols);//输出行列式的系数
struct matrix * matrix_sort(struct matrix * head, int rows, int cols);//排序行列式
struct matrix * matrix_ones(int col);//建立一个空的链表
int rows,cols; //定义行和列的变量
struct matrix * tpr;
printf( "请输入行列式的系数:\n ");
printf( "请输入行数: ");scanf( "%d ",&rows);
printf( "请输入列数: ");scanf( "%d ",&cols);
tpr = matrix_det(rows,cols);
print(tpr,rows,cols);
save_det(tpr,rows,cols);
tpr = matrix_sort(tpr,rows,cols);
printf( "\n排序后: ");
print(tpr,rows,cols);
save_det(tpr,rows,cols);
getch();
}
//用链表动态输入系数行列式
struct matrix * matrix_det(int row, int col)
{
int i,j,ji;
struct matrix * head,*prf,*prb;
head = prf = prb = (struct matrix *)malloc(LEN);
ji=row*col;
for(i=0;i <row;i++)
{
printf( "第%d行: ",i+1);
for(j=0;j <col;j++)
{
scanf( "%f ",&prf-> arr);
prf = (struct matrix *)malloc(LEN);
prb-> next = prf;
prb = prf;
}
prb-> next = NULL;
}
return (head);
}
//创建一个空链表
struct matrix * matrix_ones(int col)
{
int i;
struct matrix *head, *prf, *prb;
head = prf = prb = (struct matrix *)malloc(LEN);
for(i=0;i <col;i++)
{
prf-> arr = 1;
prf = (struct matrix *)malloc(LEN);
prb-> next = prf;
prb = prf;
}
prb-> next = NULL;
return (head);
}
//输出系数
struct matrix * print(struct matrix * head, int row, int col)
{
int i,j;
struct matrix * tpr;
tpr = head;
printf( "\n行列式:\n------\n ");
for(i=0;i <row;i++)
{
for(j=0;j <col;j++)
{
printf( "%12.2f\t ",tpr-> arr);
tpr = tpr-> next;
}
printf( "\n "); //输出换行
}
printf( "------\n ");
return 0;
}
//对行列式进行排序:冒泡法
struct matrix * matrix_sort(struct matrix * head, int row, int col)
{
int ir, ic, it,i;
float tf;
struct matrix * pf, * pb,*pf1,*pb1;