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 Multiplication 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 multiplication(int a[10][10],int b[10][10],int sum[10][10],int r,int c)


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

int main()
{
int i,r,c,a[10][10],b[10][10],sum[10][10];
FILE *fp;
clrscr();
fp=fopen("z:\\multiplicationarray.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);
multiplication(a,b,sum,r,c);
printf("\n\nMultiplication Of Matrix");
fprintf(fp,"\n\nMultiplication Of Matrix");
printf("\n");
fprintf(fp,"\n");
display_array(sum,r,c,fp);
getch();
return 0;
}
/* OUTPUT:
Enter Size Of Row::2
Enter Size Of Column::2
Array One::
Enter Value [0][0] 12
Enter Value [0][1] 52
Enter Value [1][0] 48
Enter Value [1][1] 75
12 52
48 75
Array Two::
Enter Value [0][0] 14
Enter Value [0][1] 52
Enter Value [1][0] 85
Enter Value [1][1] 45
14 52
85 45
Multiplication Of Matrix
4588 2964
7047 5871
*/