Sabtu, Februari 21, 2015

Array of C Programming

  1. One-dimensional array
    Example a is a integer variabel
    int a;

    main()
    {
    a = 27;
    printf("%d", a);
    getch();
    }

    If we want to be the a variabel as an array variabel sized 3:
    int a[3];

    main()
    {
    a[1] = 27;
    a[2] = 29;
    a[3] = 32;
    printf("%d", a[1]);
    printf("\n%d", a[2]);
    printf("\n%d", a[3]);
    getch();
    }

    So there are 3 values of a in the example of this one-dimensional array, are: 1st-a, 2nd-a, and 3rd-a. On this one-dimensional array, all that valus is defined as a ROW:
    1st-a 2nd-a 3rd-a
    or
    27 29 32

    In that 1 ROW there are 3 values, because there are 3 COLUMNs. So value in the example of this one-dimensional array can be defined as:
    a on 1st-row 1st-column a on 1st-row 2nd-column a on 1st-row 3rd-column
  2. Two-dimensional arrays
    In the example of one-dimensional array above:
    27 29 32

    added one row:
    27 29 32
    2 3 5

    So that now there are 2 ROWs 3 COLUMNs
    int a[2][3];

    main()
    {
    a[1][1] = 27;
    a[1][2] = 29;
    a[1][3] = 32;
    a[2][1] = 2;
    a[2][2] = 3;
    a[2][3] = 5;
    printf("%d", a[1][1]);
    printf("\n%d", a[1][2]);
    printf("\n%d", a[1][3]);
    printf("\n%d", a[2][1]);
    printf("\n%d", a[2][2]);
    printf("\n%d", a[2][3]);
    getch();
    }

Source: http://www.tutorialspoint.com link 1 and link 2

0 komentar: