Metrics Multiplication of two Metrics

Problem Statement 
Write a c program to scan two metrics using scanf function
multiply these metrics if possible
print the result

#include<stdio.h> int mul(int a[][10],int b[][10],int c[][10],int i,int j,int e,int r); int main() { int i,j,p,u,e,r,y; int a[10][10],b[10][10],c[10][10]; printf("enter the value of row and column resp. \n"); scanf("%d %d",&i,&j); printf("now enter the values rowvise resp.\n"); for(p=0;p<i;p++) { for(u=0;u<j;u++) { scanf("%d",&a[p][u]); } } printf("the first metrics is read as :\n"); for(p=0;p<i;p++) { for(u=0;u<j;u++) { printf("%d ",a[p][u]); } printf("\n"); } printf("now enter the numbeer of rows and column for secound metrics\n"); scanf("%d %d",&e,&r); printf("now enter values row wise \n"); for(p=0;p<e;p++) { for(u=0;u<r;u++) { scanf("%d",&b[p][u]); } } printf("the second metrics is read as :\n"); for(p=0;p<e;p++) { for(u=0;u<r;u++) { printf("%d ",b[p][u]); } printf("\n"); } y= mul(a,b,c,i,j,e,r); if(y!=0) { printf("the multiplication results in : \n"); for(p=0;p<i;p++) { for(u=0;u<r;u++) { printf("%d ",c[p][u]); } printf("\n"); } } return 0; } int mul(int a[][10],int b[][10],int c[][10],int i,int j,int e,int r) /* hence the dimention of metrice are i*j and j*r */ { int k,l,y,sum; if(j!=e) { printf("the multiplication is not possible \n"); return 0; } else { for(k=0;k<i;k++) { for(l=0;l<r;l++) { sum=0; y=0; while(y<j) { sum=sum+a[k][y]*b[y][l]; y++; } c[k][l]=sum; } } return 1; } }

No comments:

Post a Comment