Jumat, 16 Oktober 2015

Tutorial Array in C Programming

Array is a container for a number of the same type of data and the use of the indentifer. because the array is the reservoir of data, so the array is variable. Different from the usual array of variables are at kapasits reservoirs. a variable of type int can only hold an integer. bertype char variables can only meampung an ASCII character. An array of type int can hold a number bulat.larike of type char can hold a number of characters ASCII.masing each data element array is accessed by using the index or sub script.index array always starts from zero to n-1, with n states the size or capacity of the array

Array is a type of structured formations (structured user-defined types). Array or array needed to store a series of elements of the same type, structured homogeneous (homogenous structure), which is called type base (the base type).

Array also called structure that can be accessed randomly (random-access structure) because all elements of the array can be referenced at random with certain rules, namely by knowing the serial number called an index (index).


This situation can be illustrated as a student dormitory rooms, each room has a serial number and is inhabited by a student. A student can be distinguished by the serial number of room. Student dormitory Student dormitories as an array, the elements of the same type, namely a student dorm, and the room number is the index.
Arrays are of two types:

One-dimensional arrays
• Each element of the array can be accessed through an index.
• default array index starts from 0.
• The general form: Tipe_array nama_array [size];

Example program to input the value of students into a one-dimensional array

Output:





Two Dimensional arrays

• Two dimensional array is an array consisting of n rows and n columns.
• The form can be either a matrix or table.
• Declaration array: Type_array nama_array [row] [column];


Examples of program input the value of [number] into two-dimensional arrays and displays.


Output:


















Summary:
Two-dimensional array is an array consisting of m pieces rows and n columns, which form can be either a matrix or table. So that the results of their input so the same, but its output is different from its value.

Examples of two-dimensional matrix summation program





Output :




















Summary:

In a two-dimensional array is an array consisting of m pieces rows and n columns, and shaped in the form of a matrix or table.

Multy Dimensional Array

• multi-dimensional array is an array that has the size of more than two. Shape and array declaration is tantamount to an array of one-dimensional or two-dimensional array.
• The general form:

tipe_array nama_array [Dimensions1] [ukuran2] .. [ukuranN];


Example of Multidimensional Array In C

Write a C program to find sum of two matrix of order 2*2 using multidimensional 

arrays where, elements of matrix are entered by user.






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

Tidak ada komentar:

Posting Komentar