Advertisement
mfaisalpasha

2D net

Aug 23rd, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main() {
  4.    int i, j, mat1[10][10], mat2[10][10], mat3[10][10];
  5.    int row1, col1, row2, col2;
  6.  
  7.    printf("\nEnter the number of Rows of Mat1 : ");
  8.    scanf("%d", &row1);
  9.    printf("\nEnter the number of Cols of Mat1 : ");
  10.    scanf("%d", &col1);
  11.  
  12.    printf("\nEnter the number of Rows of Mat2 : ");
  13.    scanf("%d", &row2);
  14.    printf("\nEnter the number of Columns of Mat2 : ");
  15.    scanf("%d", &col2);
  16.  
  17.    /* Before accepting the Elements Check if no of
  18.     rows and columns of both matrices is equal */
  19.    if (row1 != row2 || col1 != col2) {
  20.       printf("\nOrder of two matrices is not same ");
  21.       exit(0);
  22.    }
  23.  
  24.    //Accept the Elements in Matrix 1
  25.    for (i = 0; i < row1; i++) {
  26.       for (j = 0; j < col1; j++) {
  27.          printf("Enter the Element a[%d][%d] : ", i, j);
  28.          scanf("%d", &mat1[i][j]);
  29.       }
  30.    }
  31.  
  32.    //Accept the Elements in Matrix 2
  33.    for (i = 0; i < row2; i++)
  34.       for (j = 0; j < col2; j++) {
  35.          printf("Enter the Element b[%d][%d] : ", i, j);
  36.          scanf("%d", &mat2[i][j]);
  37.       }
  38.  
  39.    //Subtraction of two matrices
  40.    for (i = 0; i < row1; i++)
  41.       for (j = 0; j < col1; j++) {
  42.          mat3[i][j] = mat1[i][j] - mat2[i][j];
  43.       }
  44.  
  45.    //Print out the Resultant Matrix
  46.    printf("\nThe Subtraction of two Matrices is : \n");
  47.    for (i = 0; i < row1; i++) {
  48.       for (j = 0; j < col1; j++) {
  49.          printf("%d\t", mat3[i][j]);
  50.       }
  51.       printf("\n");
  52.    }
  53.  
  54.    return (0);
  55. }
  56. // http://www.tutorialspoint.com/cprogramming/c_strings.htm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement