Friday, 3 May 2013

Simple Adding two matrixes by for loop in C


//simple adding two matrixes

#include<stdio.h>
void main()
{
int a[3][3],r[3][3],c[3][3],i,j,temp=0;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
        printf("enter the values for A matrics\n");
    scanf("%d",&a[i][j]);
        printf("enter the values for B matrics\n");
    scanf("%d",&r[i][j]);
        }
    }
    printf("\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            printf("%d\t",a[i][j]);
            printf("+\t");
        for(j=0;j<3;j++)
            printf("%d\t",r[i][j]);
    printf("\n");
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
    c[i][j]=a[i][j]+r[i][j];
    }
    printf("sum of above matices\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
    printf("%d\t",c[i][j]);
    printf("\n");
    }



}

No comments:

Post a Comment