You are on page 1of 2

/* ROLL NO: 1 SEM-1 ICA DIV: A

NAME : VARUN AGGARWAL SUBJECT: FOP


PROGRAM DEFINITION:Write a program to display unit matrix.
*/

#include<stdio.h>
#include<conio.h>
void read_array(int a[10][10],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter Value [%d][%d]\t",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}
}

void display_array(int a[10][10],int r,int c,FILE *fp)


{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
fprintf(fp,"%d\t",a[i][j]);
}
printf("\n");
fprintf(fp,"\n");
}
}

void unitmatrix(int a[10][10],int r,int c,FILE *fp)


{
int i,j,d=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
if(a[i][j]==1)
{
d=1;
}
else
{
d=0;
}
}
}
}
if(d==1)
{
printf("\n\nMatrix Is Unit Matrix");
fprintf(fp,"\n\nMatrix Is Unit Matrix");
}
else
{
printf("\n\nMatrix Is Not Unit Matrix");
fprintf(fp,"\n\nMatrix Is Not Unit Matrix");
}
}

int main()
{
int i,r,c,a[10][10];
FILE *fp;
clrscr();
fp=fopen("Z:\\unitmatrix.txt","w");
if(fp==NULL)
{
printf("File Could Not Open");
exit (0);
}
printf("Enter Size Of Row::");
scanf("%d",&r);
printf("Enter Size Of Column::");
scanf("%d",&c);
printf("\nMatrix Of Array ::\n\n");
fprintf(fp,"\nArray One\n\n");
read_array(a,r,c);
display_array(a,r,c,fp);
unitmatrix(a,r,c,fp);
getch();
return 0;
}
/* OUTPUT:
Enter Size Of Row::2
Enter Size Of Column::2
INPUT:
Matrix Of Array ::
Enter Value [0][0] 1
Enter Value [0][1] 1
Enter Value [1][0] 1
Enter Value [1][1] 1

1 1
1 1

Matrix Is Unit Matrix


*/