【发布时间】:2015-01-26 18:25:05
【问题描述】:
我发布了要求用户输入矩阵的代码部分,但在显示它时仅显示 0.000000 作为其元素。请帮忙找出我在哪里做的不对。
#include<stdio.h>
main(){
int i,j,m,x,c,l;
double mat[100][100],temp[100],a[100][100],lt[100][100]={0.000},ut[100][100],maximum,per[100][100];
printf("Enter the size of square matrix: ");
scanf("%d", &m);
//enter the matrix
for(i=0;i<m;i++)
{
printf("enter the row %d: \n", i+1);
for(j=0;j<m;j++){
scanf("%f",&mat[i][j]);
a[i][j]=mat[i][j];
}
}
//show matrix
printf("matrix =\n");
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf("%f\t", mat[i][j]);
}
printf("\n");
}
【问题讨论】:
-
打开编译器警告,您将了解到您需要
scanf中的%lf才能扫描double。 (但%f用于打印double很好。) -
谢谢它解决了问题。
标签: c arrays matrix printf scanf