Page 62 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 62

Unit 4: Arrays




              scanf(“%f”,&a[i][j]);                                                             Notes
              }
              printf(“Enter the elements of 2nd matrix\n”);
              for(i=0;i<2;++i)
              for(j=0;j<2;++j){
              printf(“Enter b%d%d: “,i+1,j+1);
              scanf(“%f”,&b[i][j]);
              }
              for(i=0;i<2;++i)
              for(j=0;j<2;++j){
             /* Writing the elements of multidimensional array using loop. */
              c[i][j]=a[i][j]+b[i][j]; /* Sum of corresponding elements of two
             arrays. */
              }
              printf(“\nSum Of Matrix:”);
              for(i=0;i<2;++i)
              for(j=0;j<2;++j){
              printf(“%.1f\t”,c[i][j]);
              if(j==1) /* To display matrix sum in order. */
              printf(“\n”);
              }
             return 0;
             }
             Ouput:
             Enter the elements of 1st matrix
             Enter a11: 2;
             Enter a12: 0.5;
             Enter a21: -1.1;
             Enter a22: 2;
             Enter the elements of 2nd matrix
             Enter b11: 0.2;
             Enter b12: 0;
             Enter b21: 0.23;
             Enter b22: 23;


             Sum Of Matrix:
             2.2 0.5
             -0.9 25.0
             Question
             Write a program to demonstrate two dimensional array.

          Source:  http://www.programiz.com/c-programming/c-multi-dimensional-arrays




                                           LOVELY PROFESSIONAL UNIVERSITY                                   55
   57   58   59   60   61   62   63   64   65   66   67