发了好几天编了个解线性方程组的小程序,可第一次实战就大败而归。经过半天的调试,仍找不出纠正的方法。因为并不是算法的问题,而是因为自己对编译器处理 浮点函数的方法不是很理解。明明D=0的方阵解出来不等于0了,跟踪调试发现,计算过程程序对数据进行了舍去处理,导致最终结果不对。不过如果没有浮点型 的话,这个程序应该算不错了 。
复制代码 代码如下:
#include
#include
#include
#define NUM 100
void print(void) /* 使用说明 */
{ clrscr();
printf("\n\n\n\n\n\t\t\t\t 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("\n\n\n\n\n\t\t**********Introduction********** \n");
printf("\t\t* Chose the way,please. * \n");
printf("\t\t* a : Gauss eliminant. * \n");
printf("\t\t* b : Gauss_yd eliminant. * \n");
printf("\t\t* c : Iterative way. * \n");
printf("\t\t* d : Cramer way. * \n");
printf("\t\t* e : exit. * \n");
printf("\t\t*************By__TJX************ \n");
printf("\t\tPlease choose number :\n");}
void input(double **a1,double b1[],int num) /*数据输入*/
{ int i,j,t;
double *p;