Monday, 9 July 2018

Addition of matrix of order 2 * 2 in C

/* addition of matrix */
# include <stdio.h>
void main ()
{
int a {2}{2} , b {2}{2} , c {2}{2} ;
int i , j ;
clrscr () ;
for ( i = 0 ; i < 2 ; i++ )                   /* Input of first matrix */
{
for ( j = 0 ; j < 2 ; j++ )
{
printf ("\n Enter a number:") ;
scanf ("%d", & a {i}{j}) ;
}
}
for ( i = 0 ; i < 2 ; i++ )                    /* Input of second matrix */
{
for ( j = 0 ; j < 2 ; j++ )
{
printf ("\n Enter a number:") ;
scanf ("%d", & b {i}{j}) ;
}
}
for ( i = 0 ; i < 2 ; i++ )             /* print first matrix */
{
for ( j = 0 ; j < 2 ; j++ )
printf ("%3 d", a {i}{j}) ;
printf ("\n") ;
}
for ( i = 0 ; i < 2 ; i++ )              /* print second matrix */
{
for ( j = 0 ; j < 2 ; j++ )
printf ("%3 d", b{i}{j}) ;
printf ("\n") ;
}
for ( i = o ; i < 2 ; i++ )                   /* calculation of matrix */
{
for ( j = 0 ; j < 2  ; j++ )
{
c {i}{j} = a {i}{j} + b {i}{j} ;
}
}
for ( i = 0 ; i < 2 ; i++ )
{
for ( j = 0 ; j < 2 : j++ )
printf ("%3 d", c {i}{j}) ;
printf ("\n") ;
}
getch () ;
}




No comments:

Post a Comment

Featured post

Kalgudi Interview Round!!

Those who cleared the second round of kalgudi got an email from exceller to complete their Kalgudi Interview Round. So here we will discuss ...