## Addition of Two Matrix in C Programming

Example: Write a program to add two matrix. Firstly, ask from user order of matrix( number of rows and column). Then take the elements of matrix from user as a input and print the resultant matrix

For example, if a user input order as 3,3, i.e., three rows and three columns and
First matrix
1             2             3
4             5             6
7             8             9

Second matrix:
9             8             7
6             5             4
3             2             1

then the output of the program (addition of the two matrices) is:

10           10           10
10           10           10
10           10           10

OUTPUT

## Multi-dimensional Array in C Programming

C programming language also support multidimensional arrays.

Syntax of multidimensional array declaration:

Data_type    array_name[size1][size2]…[sizeN];

For example, if we want to creates a three dimensional integer array −

int  num;

## Two-dimensional Arrays

The simplest form of multidimensional array is the two-dimensional array.

if we want to declare a two dimensional integer array of size [x][y] ( where x is a  number of rows and y is a number of columns ) you would write something as follows −

int  a;

In the above line we have created two-dimensional integer array ”a” with 3 rows and 4 columns.

In a C programming language Multidimensional arrays may be initialized by specifying bracketed values for each row.

For example we want to create an integer array with 3 rows and each row has 4 columns.

Above the nested braces indicates the intended rows.

The following initialization is equivalent to the previous example −

int a = {1,2,3,4,5,6,7,8,9,10,11,12};

which indicate the nested braces for intended row, are optional.

## Accessing Elements of Two-Dimensional Array

Create a two-dimensional array of size 3*3 and  nested loop is used to handle a two-dimensional array −

Example: Write a program to create 3*3 matrix and take all elements of matrix as an input from user and print it.

## Array in C Programming

Array is a kind of data structure that can store a elements of the same type. Arrays stores the elements in a contiguous memory locations.

Array is a collection of similar type elements

For example: we want to declare 100 integer variable

Instead of declaring 100 individual variables, such as

int number0, number1,number2,number3, … …., number99;

you declare one integer array variable such as

int number;

here number is an integer array of size 100, means this array can store 100 integer value.

Array indexing starts from index 0 to n-1. Means first integer number store in array number, second integer number store in array number, third integer number store in array number, and so on. Here 100th  number store in array numbers.

## Declaring Array

Syntax of declare an array in C:

DataType  arrayName [ arraySize ];

This is called a single-dimensional array.

The arraySize is an integer constant greater than zero.

datatype can be any valid C data type.

Example: write a program to create integer array and store 5 integer number and print.

Example: write a program to take 5 number from user and store integer number in integer array and print.

## Another way to Initialize Array

We can also initialize array by this way:

int num = { 54 , 4,  13,  2,  17 };

above integer array num, stores five numbers. Where num store 54, num store 4….. , & num store 17.

## PHP Array Tutorial

An array is a data structure or a rather a collection of data that contains a group of elements. Typically these elements are all of the same data types or different data types.

for example:
If a complex has thirty flats each flat having same features then the whole complex is considered to be an Array.
Each of thirty flat is an element of that array and as each flat shares the same type of features – those are considered as same data types.

So, in a programming language like PHP, the array is a collection of different type of value in a single variable. You also can say a string is one kind of array because string consists of multiple characters.

Note: In programming languages like ‘C’, only one type of value (integer or string or float etc.) can be stored in an array and must be defined at the beginning of the program, but in PHP we can store different types of value (string, integer, Boolean, null, object, float) in a single array.

define an array
An array is a data structure that stores one or more different type of values in a single variable.

Syntax of an array

Note: Most of developers use syntax type II for robust programming support.

print an array

Note: this two functions (print_r() and var_dump()) are also debugging function in PHP (about debugging function will be discussed later)

Output:

now 0 1 2 3 are index of the value means 0 1 2 3 in this position apple mango banana lemon are stored respectively.
Index means which is used to identify the particular one value/element in the array.

Explanation:
We can find a house by its address but when we try to find a room in an apartment there must be a number or floor division which separates every room/house from each other rooms/houses.

In similar way multiple value stores in single array separates by a unique index number. It is also called an ‘ARRAY IDENTIFIRE’. Index, always starts from 0 and automatically incremented, but you also set index manually.

Example:
You can return particular one element of any array by using index number of this array.

In another way you also define array in PHP:

Display an array

This is the example of manual index value. We can also use in this manner.

Result

How to know the length or size of an unknown array

Output

Printing array using loop in PHP

Result

Using FOREACH loop

Result