矩阵加法使用c

时间:2015-10-10 22:06:10

标签: c matrix addition

我正在分配使用C添加矩阵的工作,我使用的是Dev C ++ IDE 5.71版本,我尝试使用此代码,但它没有编译

#include "stdio.h"

int main(){
    int a, b ,c ,d, mat1[20][20],mat2[20][20], matAdd[20];

    //a = row number ,b = column no 
    printf("Enter the number of rows and columns:\n");

    scanf("%d%d", &a,&b);

    printf("Enter elements of matrix one:\n");

    for (c =0; c < a; c++){
        for (d=0; d < b; d++){
            scanf("%d", &mat1[c][d]);
         }
    }
    printf("Enter elements of matrix two:\n");

    for (c =0; c < a; c++){
        for (d = 0; d < b; d++){
            scanf("%d", &mat2[c][d]);
        }
    }

    printf("Addition of the two matrices is below:\n");

    for (c =0; c < a; c++){
        for (d=0; d < b; d++){

        matAdd[c][d] = mat1[c][d] + mat2[c][d]; 
        printf("%d\t",matAdd[c][d]); 
    }
    printf("%n");
    getch();
    return 0 ;
}

以下是我收到的错误。

Line:35 Col:12 [Error] subscripted value is neither an array nor pointer nor vector
Line:36 Col:26 [Error] subscripted value is neither an array nor pointer nor vector
Line:45 Col:1 [Error] expected declaration or statement at end of input

1 个答案:

答案 0 :(得分:0)

有一个拼写错误:您的定义public class CustomerOrder extends JPanel { //... } 应为matAdd[20]