Code Scrappers


Matrix Addition - C program


                    #include<stdio.h>
                    #include<stdlib.h>

                    void main()
                    {
                        int a[8][8], b[8][8], c[8][8];

                        int i, j, m, n;

                        printf("\n Enter the no. rows of the matrix : ");

                        scanf("%d", &m);

                        printf("\n enter the no. of columns of matrix : ");

                        scanf("%d", &n);

                        printf(" enter the 1st matrix");

                        for(i=0;i<m;i++)
                        {
                            for(j=0;j<n;j++)
                            {
                                scanf("%d",&a[i][j]);

                            }

                        }

                        printf("\nEnter the 2nd matrix");

                        for(i=0;i<m;i++)
                        {
                            for(j=0;j<n;j++)
                            {
                                scanf("%d",&b[i][j]);

                            }

                        }

                        for(i=0;i<m;i++)
                        {
                            for(j=0;j<n;j++)
                            {
                                c[i][j] = a[i][j] + b[i][j];

                            }

                        }

                        printf("\nThe addition of two matrix is\n");

                        for(i=0;i<m;i++)
                        {
                            for(j=0;j<n;j++)
                            {
                                printf("%d\t",c[i][j]);

                            }
                            printf("\n");

                        }

                    }


                



Output

            Enter the no. of rows of the matrix : 2

            enter the no. of columns of the matrix : 2

            Enter the First matrix
            1
            2
            3
            4

            Enter the Second matrix
            2
            4
            4
            2

            The Addition of two matrix is
            3       6
            7       6