高斯消元法解线性方程组 C实现

时间:2022-05-26 13:40:16
【文件属性】:
文件名称:高斯消元法解线性方程组 C实现
文件大小:1KB
文件格式:CPP
更新时间:2022-05-26 13:40:16
C语言 作业 #include #include #include using namespace std; double A[1010][1010]; double B[1010]; double l; int main() { int n; printf("Please enter the order of the matrix. If you want to exit, press zero:\n"); while(~scanf("%d",&n)) { if(n==0) return 0; printf("Press the input matrix from top to bottom:\n"); for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { scanf("%lf",&A[i][j]); } } for(int i=1; i<=n; i++) { scanf("%lf",&B[i]); } for(int i=1; i=1; i--) { for(int j=n; j>i; j--) { B[i]-=A[i][j]*B[j]; } B[i]/=A[i][i]; } for(int i=1; i<=n; i++) { printf("%f\n",B[i]); } printf("Please enter the order of the matrix. If you want to exit, press zero:\n"); } return 0; }

网友评论