google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to check whether the matrix is an identity matrix or not in c - 2nd puc computer science

Write a program to check whether the matrix is an identity matrix or not in c

Write a program to check whether the matrix is an identity matrix or not in c

c program to check whether a matrix is an identity matrix or not,write a c program to check whether a matrix is an identity matrix or not,write a c program to check whether a matrix is identity matrix,c program to check whether a matrix is identity or not

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10][10],i,r,c,j,sum=0,flag=1;

clrscr();

printf("Enter the order of matrix: \n");

scanf("%d%d",&r,&c);

if(r==c)

{

printf("Enter the elements\n");

for(i=0;i<r;i++)

         for(j=0;j<c;j++)

                  scanf("%d",&a[i][j]);

printf("Entered Matrix is\n");

for(i=0;i<r;i++)

{

                  for(j=0;j<c;j++)

                           printf("%d\t",a[i][j]);

                           printf("\n");

}

 

for(i=0;i<r;i++)

{

                  for(j=0;j<c;j++)

                  {

                           if(a[i][j]!=1&&a[j][i]!=0)

                           {

                           flag=0;

                           break;

                           }

                  }

}

if(flag==1)

         printf("It is an identity matrix");

else

         printf("It is not an identity matrix");

}

else

printf("It is not a square matrix to find identity matrix");

getch();

}

Output:

 

run 1:

Enter the order of matrix:

2

2

Enter the elements

1 0

0 1

Entered Matrix is

1       0

0       1

It is an identity matrix

 

run 2:

Enter the order of matrix:

2

2

Enter the elements

1 2

0 1

Entered Matrix is

1       2

0       1

It is not an identity matrix

 

run 3:

Enter the order of matrix:

2

3

It is not a square matrix to find identity matrix


Write a program to check whether the matrix is an identity matrix or not in c Write a program to check whether the matrix is an identity matrix or not in c Reviewed by Vision Academy on December 22, 2021 Rating: 5

2 comments:

CheckOut

Powered by Blogger.