1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include<stdio.h> int main() { int A[3][3]; printf("enter your [3]*[3]matrix =9 elements: \n"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { scanf("%d",&A[i][j]); } } printf("\nA matrix is: \n"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { printf("%d ",A[i][j]); } printf("\n"); } int B[3][3]; printf("enter your [3]*[3] matrix =9 elements: \n"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { scanf("%d",&B[i][j]); } } printf("\nB matrix is: \n"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { printf("%d ",B[i][j]); } printf("\n"); } printf("\nC=AxB matrix is: \n"); int C[3][3]; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { int temp=0; for(int k=0;k<3;k++) { temp+=A[i][k]*B[k][j]; } C[i][j]=temp; } } for(int i=0;i<3;i++) { for(int k=0;k<3;k++) { printf("%d ",C[i][k]); } printf("\n"); } } |
Friday, 20 March 2015
Matrix Multiplication using 2D Array
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment