Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

addition of two matrix in c

#include<stdio.h>
void main(){
    int r,c,i,j,a[100][100],b[100][100],sum[100][100];
    printf("Enter number of rows : ");
    scanf("%d",&r);
    printf("Enter number of columns : ");
    scanf("%d",&c);
    
    printf("##### First Matrix ###### 
");
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&a[i][j]);
        }
    }
    printf("##### Second Matrix ###### 
");
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&b[i][j]);
        }
    }
    //additon of two matrix
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            sum[i][j] = a[i][j] + b[i][j];
        }
    }
    //to show the resultant matrix
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            printf("%d	",sum[i][j]);
        
        if(j == c-1){
            printf("
");
        }
        }
    }
    
}
 
PREVIOUS NEXT
Tagged: #addition #matrix
ADD COMMENT
Topic
Name
9+9 =