Some More Basic Operations

The get, set, min, max, sum and average operations.

Functions :

  • getElement()

  • setElement()

  • getMin()

  • getMax()

  • getSum()

  • getAverage()

getElement() function:

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

setElement() function:

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

getMax() function:

getMin() function:

getSum() function:

getAverage() function:

Contributed by Nitin Ranganath

Last updated

Was this helpful?