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 7254995 commit da60c42
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions source/_posts/T2.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ _<span style="color: #ADD8E6">References:</span>_

- In this example “age” is the array of type “int” having 5 elements.

- Each element of the array is identified by the subscript number starting from 0 - 4.
- Each element of the array is identified by the subscript number starting from 0 to 4.

- If the address of the age[0] is 2120d and the size of int be 2 bytes,

Expand Down Expand Up @@ -152,74 +152,56 @@ Element[9] = 109.
```


**Example: Calculate Average**
**Example 2: Calculate Average**

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

#include <stdio.h> int main() {

int marks[10], i, n, sum = 0, average;

printf("Enter number of elements: "

scanf("%d", &n);

for(i=0; i<n; ++i)

{

printf("Enter number%d: ",i+1);

scanf("%d", &marks[i]);


// adding integers entered by the user to the sum variable

sum += marks[i];

}

average = sum/n;

printf("Average = %d", average);

return

}
```

**Output**

```bash
Enter n: 5

Enter number1: 45

Enter number2: 35

Enter number3: 38

Enter number4: 31

Enter number5: 49

Average = 39
```



Find the Largest/Smallest of the Elements of an Array
**Example 3: Find the Largest/Smallest of the Elements of an Array**


- We set the largest to the value of the first element of the array.

- Then we compare this value to each of the other elements in the array.

- If one is larger, we replace the value in largest with the value and continue to check the rest of the array.


Flow chart to find the largest of the array

![image](https://github.com/user-attachments/assets/71a096de-d626-49d2-a298-19a0ea6822bb)

Expand Down

0 comments on commit da60c42

Please sign in to comment.