// program to know a matrix is identity or not
//to know a matrix is identity or not
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],order,i,j,first=0,second=0;
printf("enter order\n");
scanf("%d",&order);
printf("enter matrix elements\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("the matrix is\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
if(i==j)
{
first=first+1;
}
else
{
second=second+a[i][j];
}
}
}
if(first==order && second==0)
{
printf("it is identity matrix\n");
}
else
{
printf("it is not");
}
getch();
}
//to know a matrix is identity or not
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],order,i,j,first=0,second=0;
printf("enter order\n");
scanf("%d",&order);
printf("enter matrix elements\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("the matrix is\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
if(i==j)
{
first=first+1;
}
else
{
second=second+a[i][j];
}
}
}
if(first==order && second==0)
{
printf("it is identity matrix\n");
}
else
{
printf("it is not");
}
getch();
}
No comments:
Post a Comment