C PRACTICAL / CHECK A SQUARE MAGIC MATRIX.

hello friends....

TAKE THE FIRST STEP TO KNOWLEDGE FRIENDS BECAUSE KNOWLEDGE IS FREE.

>> /* WRITE A C PROGRAM TO CHECK A SQUARE MAGIC MATRIX. */

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,a[3][3],sum1,sum2,sum3=0;
    clrscr();

    // store matric value

    printf("enter your matrix : \n");
    for(i=0; i<3; i++)
    {
           for(j=0; j<3; j++)
           {
        scanf("%d",&a[i][j]);
            } // second for close
    } // first for close
    printf("\n\n");
    // declaration of matrix

    for(i=0; i<3; i++)
    {
           for(j=0; j<3; j++)
           {
          printf("%d\t",a[i][j]);
            } // seconf for close
            printf("\n");
    } // first for close

    // row, colum and diagonal calculation

    // row calculation
    sum1=0;
    for(i=0; i<1; i++)
    {
           for(j=0; j<3; j++)
          {
        sum1 = a[i][j] + sum1;
          } // seconf for close
    } // first for close

    // colum calculation
    sum2 = 0;
    for(i=0; i<3; i++)
    {
            for(j=0; j<1; j++)
           {
         sum2 = a[i][j] + sum2;
            } // second for close
    } // first for close

    // diagonal calculation
    sum3 = a[0][0] + a[1][1] + a[2][2];

    // comparision and check

    if(sum1==sum2)
    {
           if(sum1==sum3)
           {
          printf("this is magic square matrix\n");
           } // second if close
          else
          {
          printf("this is NOT square matrix !!!");
          }
    }  // first if close
    else{
      printf("this is NOT square matrix !!!\n");
    }

    getch();

}


   /*  OUTPUT  */
======================

enter your matrix :
4
9
2
3
5
7
8
1
6


4          9          2
3          5          7
8          1          6
this is magic square matrix

* * * * * * * * * * * * * *

>> IF YOU LIKE THIS BLOG, PLEASE SHARE AND SUBSCRIBE. ALSO COMMENT  FOR THIS BLOG.
>> IF YOU HAVE ANY QUESTIONS PLEASE ASK IN COMMENT.
>> IF YOU WANT TO LEARN HTML WITH OUTPUT, SO VISIT THIS BLOG
      https://dnpwebdeveloper.blogspot.com/
>> IF YOU WANT TO LEARN C++ PROGRAM WITH OUTPUT, SO VISIT THIS BLOG
>> MY INSTAGRAM ID : dnp176

Comments