Saturday, 9 June 2012

C Program To Generate Unit Matrix

Posted by Unknown On 11:49 | 1 comment

#include<stdio.h>
main()
{
int a[10][10],i,j,m,n;
printf("\nEnter the order:");
scanf("%d%d",&m,&n);
printf("\nEnter the elements:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
a[i][j]=1;
else
a[i][j]=0;
}
}
printf("\nThe unit matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}                                                                                                                                                                                                                                                                                                                                  

1 comment:

Blogroll

Blogger templates

About