Untitled
unknown
plain_text
2 years ago
2.1 kB
3
Indexable
Never
// Online C compiler to run C program online #include <stdio.h> ADDITION(int a[][4], int b[][4], int n) { int i,j,c[4][4]; printf("\n Addition of Matrix is:\n"); for(i=0;i<n;i++) for(j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",c[i][j]); } printf("\n"); } } SUBSTRACTION(int a[][4], int b[][4], int n) { int i,j,c[4][4]; printf("\n Substraction of Matrix is:\n"); for(i=0;i<n;i++) for(j=0;j<n;j++) c[i][j]=a[i][j]-b[i][j]; for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",c[i][j]); } printf("\n"); } } MULTIPLICATION(int a[][4], int b[][4], int n) { int i,j,k,c[4][4]; printf("\n Multiplication of Matrix is:\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { c[i][j]=0; for(k=0;k<n;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",c[i][j]); } printf("\n"); } } int main() { int a[4][4],b[4][4],c[4][4]; int i,j,n,choice; char ch; printf("\n Enter size of matrix"); scanf("%d",&n); printf("\n Enter the elenemts in 1st matrix"); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("\n Enter the elenemts in 2nd matrix"); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&b[i][j]); do { printf("\n 1. Addition"); printf("\n 2. Substraction"); printf("\n 3. Multiplication"); printf("\n Enter Your choice"); scanf("%d",&choice); switch(choice) { case 1: ADDITION(a,b,n); break; case 2: SUBSTRACTION(a,b,n); break; case 3: MULTIPLICATION(a,b,n); break; } printf("\n Do You want to Continue Y or N"); scanf("\n%c",&ch); }while(ch=='Y'||ch=='y'); return 0; }