c - C程序中出现多个错误

标签 c

我必须编写一个程序,要求用户使用 C 语言提供 2 个 3x3 的数组,然后打印包含每个位置总和的 sum_matrix。

我还必须将它分成 3 个函数,我已经做到了,但它似乎充满了错误,我无法真正让它工作。

PS:righe表示线条,colonne列,inserisci插入,somma总和,stampa打印。

#include <stdio.h>
#include <stdlib.h>

void leggi_matrice(int MAT[][], int nRighe, int nColonne);
void somma(int MAT1[][N], int MAT2[][], int nRighe, int nColonne);
void stampa_matrice(int MAT[][], int dim, int nRighe, int nColonne);

int main ()
{
    int mat_somma[][];
    int mat1[][];
    int mat2[][];
    int nRighe = 3;
    int nColonne =3;

    leggi_matrice( mat1[][], nRighe, nColonne);
    leggi_matrice(mat2[][], nRighe, nColonne);
    void somma(mat1[][], mat2[][], nRighe, nColonne);
    void stampa_matrice(mat_somma[][], nRighe, nColonne);

    printf("\n\n\n");
    system("PAUSE");
    return 0;
}


void leggi_matrice(int MAT[][], int nRighe, int nColonne)
{
     for (i=0 ; i<nRighe ; i ++);
     for (j=0 ; j<nColonne ; j ++);
     {
         printf("Inserisci elemento");
         scanf("%d", & MAT[i][j]);
     }
}


void somma(int MAT1[][], int MAT2[][], int nRighe, int nColonne);
{
     int mat_somma[][];
     for (i=0 ; i<nRighe ; i ++);
     for (j=0 ; j<nColonne ; j ++);
     {
         mat_somma[i][j] = MAT1[i][j] + MAT2[i][j];
     }
}


void stampa_matrice(int MAT[][], int dim, int nRighe, int nColonne)
{
     int mat_somma[][];
     for (i=0 ; i<nRighe ; i ++);
     for (j=0 ; j<nColonne ; j ++);
     {
         printf ("%3d",mat_somma[i][j];
     }
}

最佳答案

for (i = 0; i < nRighe; i++);    
for (j = 0; j < nColonne; j++);
{
    printf ("%3d", mat_somma[i][j];
}
  • 您将使用 ; 结束 for 循环,并且在本地范围内,这些 {},您将获得未声明的变量,这些变量正在使用:ij
  • 您需要在for语句中定义ij的数据类型。
  • 正如 Paul Griffiths 提到的,printf() 函数末尾缺少一个括号。

我认为你的意思是这样做:

for (int i = 0; i < nRighe; i++)
{
    for (int j = 0; j < nColonne; j++)
    {
        printf ("%3d", mat_somma[i][j]);
    }
}

或者简写版本:

for (int i = 0; i < nRighe; i++)
    for (int j = 0; j < nColonne; j++)
        printf ("%3d", mat_somma[i][j]);

关于c - C程序中出现多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19453940/

相关文章:

c - 哪些规则应该在 GNU make 中使用 CFLAGS

c - 确定 x/y 网格索引的算法

c - C 中的 XOR 相同数据导致非零值。为什么?

c - switch 语句结束

c - C中四元数到欧拉角以及欧拉角到四元数

c - 我创建的数组的大小超出预期

无法从 Makefile 链接静态库

c - While 循环在第一个循环后不接收数据

c - IAR Expression 预期表达式

c - 从文件中删除