one dimensional array c programming language - C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Thursday, June 15, 2017

one dimensional array c programming language

More than one item can be given a variable name utilizing only one subscript and such a variable is called a single subscripted variable or a one dimensional [1D] array. 
                                                                                  

In mathematics we usually deal with variables that are single subscripted.  For example we use the equation,
                                                                  
To calculate the average of n values of x. the subscripted variable x refers to the element of x. in  C single  subscripted variable x can be expressed as
X[1],x[2],x[3] …………………………………………………………………………………. x[n]

The subscript can be being with number 0, that is
X[0]

For example, if we want to represent a set of five numbers, say ( 10, 15, 20, 30, 40 ) by an one dimensional array variable number, then we may declare the variable number as follows
number  [0]
number  [1]
number  [2]
number  [3]
number  [4]

The values to the array elements can be assigned as :
number  [0] = 10;
number  [1]  = 15;
number  [2]  =  20;
number  [3]  = 30;
number  [4]  = 40;

This would cause the array (number ) to store the values as shown below :
number  [0]     10
number  [1]     15
number  [2]     20
number  [3]     30
number  [4]     40

these elements may be used in programs just like any other c variable. Such as the following are valid statements:
add = number[0] + 100;
add = number [1] * 100;
add = number [2] / 5;
add = number[3]  –  50;
add = number[1]  +  number [2];
number[5] = number[3]  * number [4];
number[3] = number[5] / number[1];




No comments:

Post a Comment