当前位置: 编程技术>c/c++/嵌入式
C语言解线性方程的四种方法
来源: 互联网 发布时间:2014-10-22
本文导语: 发了好几天编了个解线性方程组的小程序,可第一次实战就大败而归。经过半天的调试,仍找不出纠正的方法。因为并不是算法的问题,而是因为自己对编译器处理 浮点函数的方法不是很理解。明明D=0的方阵解出来不等于0了...
发了好几天编了个解线性方程组的小程序,可第一次实战就大败而归。经过半天的调试,仍找不出纠正的方法。因为并不是算法的问题,而是因为自己对编译器处理 浮点函数的方法不是很理解。明明D=0的方阵解出来不等于0了,跟踪调试发现,计算过程程序对数据进行了舍去处理,导致最终结果不对。不过如果没有浮点型 的话,这个程序应该算不错了 。
#include
#include
#include
#define NUM 100
void print(void) /* 使用说明 */
{ clrscr();
printf("nnnnntttt Introduction n");
printf("t*--------------------------------------------------------------*n");
printf("t* This program was design for compute linear equations. *n");
printf("t* The way of use it is very simple. *n");
printf("t* First : Input the number of the equation;(Input 0 to exit) *n");
printf("t* Second: Input the coefficient of every eqution; *n");
printf("t* Third : Input the constant of every eqution; *n");
printf("t* Last : Chose the way you want use to solve the equtions; *n");
printf("t* That's all, input any key to run it . . . *n");
printf("t*-------------------------By__TJX------------------------------*n");
getch(); }
void chose(void) /*选择计算方法*/
{ clrscr();
fflush(stdin);
printf("nnnnntt**********Introduction********** n");
printf("tt* Chose the way,please. * n");
printf("tt* a : Gauss eliminant. * n");
printf("tt* b : Gauss_yd eliminant. * n");
printf("tt* c : Iterative way. * n");
printf("tt* d : Cramer way. * n");
printf("tt* e : exit. * n");
printf("tt*************By__TJX************ n");
printf("ttPlease choose number :n");}
void input(double **a1,double b1[],int num) /*数据输入*/
{ int i,j,t;
double *p;
char de1,de2;
do{
printf("Please input array a[%d][%d]: n",num,num);
printf("Warn: The first number of the array mustn't contain zero! n");
for(i=1;i
代码如下:
#include
#include
#include
#define NUM 100
void print(void) /* 使用说明 */
{ clrscr();
printf("nnnnntttt Introduction n");
printf("t*--------------------------------------------------------------*n");
printf("t* This program was design for compute linear equations. *n");
printf("t* The way of use it is very simple. *n");
printf("t* First : Input the number of the equation;(Input 0 to exit) *n");
printf("t* Second: Input the coefficient of every eqution; *n");
printf("t* Third : Input the constant of every eqution; *n");
printf("t* Last : Chose the way you want use to solve the equtions; *n");
printf("t* That's all, input any key to run it . . . *n");
printf("t*-------------------------By__TJX------------------------------*n");
getch(); }
void chose(void) /*选择计算方法*/
{ clrscr();
fflush(stdin);
printf("nnnnntt**********Introduction********** n");
printf("tt* Chose the way,please. * n");
printf("tt* a : Gauss eliminant. * n");
printf("tt* b : Gauss_yd eliminant. * n");
printf("tt* c : Iterative way. * n");
printf("tt* d : Cramer way. * n");
printf("tt* e : exit. * n");
printf("tt*************By__TJX************ n");
printf("ttPlease choose number :n");}
void input(double **a1,double b1[],int num) /*数据输入*/
{ int i,j,t;
double *p;
char de1,de2;
do{
printf("Please input array a[%d][%d]: n",num,num);
printf("Warn: The first number of the array mustn't contain zero! n");
for(i=1;i