Wednesday 26 October 2011

implementation of addition of two matrix

/*
ALGORITHM:

Matadd(a,b,m,n)
1 for (i=1 to m
2 for(j= 1 to n)
3c[i][j] = a[i][j]+b[i][j]
4 exit
*/
//program implemented by shadab khan
#include <stdio.h>
#include <conio.h>
Void main()
{
Int a[2][2],b[2][2],s[2][2],i,j;
clrscr ();
printf("enter first matrix: \n");
for( i=1; i<=2; i++)
{
            for( j=1; j<=2; j++)
            {
            printf("Enter %d%d", i,j, "element:");
            scanf("%d",&a[i][j]);
            }
}
printf("enter second matrix: \n");
for(i=1;i<=2;i++)
{
            for(j=1; j<=2;j++)
            {
            printf( "enter  %d%d",i + 1 ,j + 1 , "element:");
            scanf("%d",&b[i][j])  ;
            }
}
for(i=1;i<=2;i++)
{
            for(j=1;j<=2;j++)
            {
            s[i][j]= a[i][j]+b[i][j];
            }
}
printf("The addition matrix is:\n");
for(i=1;i<=2;i++)
{
            for(j=1;j<=2;j++)
            {
            printf("%d\n",s[i][j] );
            }
}
getch ();
}

No comments:

Post a Comment