CS561-SPRING 2002

TOPIC:CS105-ARRAYS

 

                                       Here is a simple program that demonstrates the use of one dimensional and two dimensional arrays and data manipulation in them. Two dimensional arrays are trickier to handle that their one dimensional counterparts and care must be exercised while doing the same.

#include<stdio.h>

void main()

{

      int a,one_dim[10], two_dim[3][3];

          for (a=0; a<10; a++)  // assigning values to one dimensional array

                       {  one_dim [a] = a; }  // end for loop

 a = 0; // resetting value of integer variable ‘a’ to zero.

for (int j=0;j<3;j++) // row operations for two dimensional array

      {        for (int k=0;k<3;k++) // col operations for two dimensional array

              { two_dim[j][k] = a;

                  a++;     }  // end inner for loop.

         }  // end outer for loop.

   /*    WRITE CODE TO PRINT OUT VALUES OF BOTH   ARRAYS HERE, TO VIEW THE   

        CONTENTS OF EACH ARRAY            */

}  // end main program.

View code to insert

                         <=PREV                                       HOME                                               NEXT=>