/*
 * BIT8122/BCT8121 Data Structures - CAT 2
 * Selected array operations: linear search and average calculation.
 * Marks has capacity 10, but only the first 7 elements are initialized.
 */
#include <stdio.h>

#define MAX_MARKS 10

int main(void)
{
    int Marks[MAX_MARKS] = {12, 20, 13, 14, 16, 17, 8};
    const int count = 7;
    int searchValue;
    int foundIndex = -1;
    int sum = 0;
    double average;

    for (int i = 0; i < count; i++) {
        sum += Marks[i];
    }
    average = (double)sum / count;

    printf("Average mark: %.2f\n", average);
    printf("Enter a mark to search for: ");

    if (scanf("%d", &searchValue) != 1) {
        fprintf(stderr, "Invalid input. Enter an integer mark.\n");
        return 1;
    }

    for (int i = 0; i < count; i++) {
        if (Marks[i] == searchValue) {
            foundIndex = i;
            break;
        }
    }

    if (foundIndex >= 0) {
        printf("%d was found at position %d (index %d).\n",
               searchValue, foundIndex + 1, foundIndex);
    } else {
        printf("%d was not found in the marks array.\n", searchValue);
    }

    return 0;
}
