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 Prinf Subtraction Of 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 subtraction(int a[10][10],int b[10][10],int sub[10][10],int r,int c)


{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sub[i][j]=a[i][j]-b[i][j];
}
}
}

int main()
{
int i,r,c,a[10][10],b[10][10],sub[10][10];
FILE *fp;
clrscr();
fp=fopen("Z:\\subtractionarray.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("\nArray One::\n\n");
fprintf(fp,"\nArray One\n\n");
read_array(a,r,c);
display_array(a,r,c,fp);
printf("\nArray Two::\n\n");
fprintf(fp,"\nArray Two\n\n");
read_array(b,r,c);
display_array(b,r,c,fp);
subtraction(a,b,sub,r,c);
printf("\n\nSubtraction Of Matrix");
fprintf(fp,"\n\nSubtraction Of Matrix");
printf("\n");
fprintf(fp,"\n");
display_array(sub,r,c,fp);
getch();
return 0;
}
/* OUTPUT:
Enter Size Of Row::2
Enter Size Of Column::2
Array One::
Enter Value [0][0] 1
Enter Value [0][1] 2
Enter Value [1][0] 3
Enter Value [1][1] 4
1 2
3 4
Array Two::
Enter Value [0][0] 2
Enter Value [0][1] 1
Enter Value [1][0] 4
Enter Value [1][1] 3
2 1
4 3
Subtraction Of Matrix
-1 1
-1 1
*/