# Some More Basic Operations

### Functions :&#x20;

* getElement()
* setElement()
* getMin()
* getMax()
* getSum()
* getAverage()

#### getElement() function:&#x20;

```c
int getElement(int a[], int n, int index) {
    if (index >= 0 && index < n) {
        return a[index];
    } else {
        return -1;
    }
}
```

#### setElement() function:&#x20;

```c
void setElement(int a[], int n, int index, int value) {
    if (index >= 0 && index < n) {
        a[index] = value;
    } else {
        printf("Wrong index !");
    }
}
```

#### getMax() function:

```c
int getMax(int a[], int n) {
    int max = a[0];
    for (int i = 0; i < n; i++) {
        if (a[i] > max) {
            max = a[i];
        }
    }
    return max;
}
```

#### getMin() function:&#x20;

```c
int getMin(int a[], int n) {
    int min = a[0];
    for (int i = 0; i < n; i++) {
        if (a[i] < min) {
            min = a[i];
        }
    }
    return min;
}
```

#### getSum() function:&#x20;

```c
int getSum(int a[], int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum = sum + a[i];
    }
    return sum;
}
```

#### getAverage() function:

```c
float getAverage(int a[], int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum = sum + a[i];
    }
    float average = sum/n; 
    return average;
}
```

Contributed by Nitin Ranganath


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nitinranganath.gitbook.io/data-structures/arrays/some-more-basic-operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
