Skip to content

Commit

Permalink
Update T2.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nehal-Khan-29 authored Aug 27, 2024
1 parent 3d580de commit 9cfbb06
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions source/_posts/T2.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,36 @@ _<span style="color: #ADD8E6">References:</span>_

<hr>
<hr>
**COMPETITIVE PROGRAMMING**

**CP AUTHORS: KAUSHIK KUMBHAT and SHYAM PRASATH**
**<span style="color: #90EE90; font-size: 1.5rem;">Competitive Programming</span>**
**<span style="color: #ADD8E6; font-size: 1rem;">Authors - Kaushik Kumbhat and Shaym Prasanth</span>**

**Arrays**

• An array is a collection of data storage locations, each having the same data type and the same name.

• An array can be visualized as a row in a table, whose each successive block can be thought of as memory bytes containing one element.
**<span style="color: #ADD8E6; font-size: 1rem;">Arrays</span>**

- An array is a collection of data storage locations, each with the same data type and name.
-
- An array can be visualized as a row in a table, whose each successive block can be thought of as memory bytes containing one element.
-
- Each storage location in an array is called an array element.

• Each storage location in an array is called an array element.



**Arrays are of two types:**
**<span style="color: #ADD8E6; font-size: 1rem;">Arrays are of two types:</span>**

Single or One dimensional arrays.
- Single or One-dimensional arrays.

• Multidimensional eg. two dimensional arrays.
- Multidimensional eg. two-dimensional arrays.


Single Dimensional Arrays

**<span style="color: #ADD8E6; font-size: 1rem;">Single Dimensional Array</span>**

A single dimensional array has only a single subscript.
- A single-dimensional array has only a single subscript.

A subscript is a number in brackets that follows an array name.
- A subscript is a number in brackets that follows an array name.

This number can identify the number of individual elements in the array.
- This number can identify the number of individual elements in the array.

Individual array elements are stored in sequential memory locations.
- Individual array elements are stored in sequential memory locations.

![image](https://github.com/user-attachments/assets/70a2b23d-545f-45f7-b4d8-348a002aa0b5)

Expand All @@ -107,31 +107,33 @@ Single Dimensional Arrays
3. If the address of the age[0] is 2120d and the size of int be 2 bytes,


then the address of next elements shall be

Then the address of the next elements shall be
```bash
age[1] is 2122d
age[2] is 2124d
age[3] is 2126d
age[4] is 2128d

```

Accessing array elements

An element is accessed by indexing the array name.
- An element is accessed by indexing the array name.

This is done by placing the index of the element within square brackets after the name of the array.
- This is done by placing the index of the element within square brackets after the name of the array.

For example:

double salary = balance[9];

The above statement will take 10th element from the array and assign the value to salary variable.
- The above statement will take the 10th element from the array and assign the value to the salary variable.

![image](https://github.com/user-attachments/assets/4f357c8e-ec6d-4f09-8820-63e538960fd5)



When the above code is compiled and executed, it produces the following result:
- When the above code is compiled and executed, it produces the following result:

```bash
Element[0] = 100.

Element[1] = 101.
Expand All @@ -151,10 +153,10 @@ Element[7] = 107.
Element[8] = 108.

Element[9] = 109.

```


Example : Calculate Average
Example: Calculate Average

// Program to find the average of n numbers using arrays

Expand Down

0 comments on commit 9cfbb06

Please sign in to comment.