Write a C program To determine whether a matrix is identity or Not!!

 TASK-

Write a C program To determine whether a matrix is identity or Not!!

IDENTITY MATRIX: A matrix having 1 on diagonal entries and 0 on non diagonal entries.


CODE:

#include<stdio.h>

int main(){

int r,c,p1=0,p2=0,d,x;

printf("Enter the Dimension of matrix\n");

scanf("%d",&d);

int n[d][d];

printf("Enter the entries \n");

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

{

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

{

printf("Enter entry [%d %d]",r+1,c+1);

scanf("%d",&n[r][c]); 

printf("\n");

}

}

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

{

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

{

if (r==c)

{

  if (n[r][c]==1)

  p1++;

}

if (r!=c)

{

if (n[r][c]==0)

p2++;

}

}

}

     x=(d-1)*d; //There would be (d-1)*d zeros in an identity matrix where d is dimension

if (p1==d&&p2==x)

printf("Its an identity matrix");

else 

printf("Its not an identity matrix");

}

EXPECTED OUTPUT:



NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

1 Comments

Post a Comment
Previous Post Next Post