x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

#include <stdio.h>
#include <stdlib.h>

// Define the structure for a student
struct Student {
    char name[50];
    int marks;
};

// Function to compute the average marks
float computeAverage(struct Student students[], int numStudents) {
    int totalMarks = 0;

    for (int i = 0; i < numStudents; i++) {
        totalMarks += students[i].marks;
    }

    return (float)totalMarks / numStudents;
}

// Function to display students above and below the average marks
void displayAboveBelowAverage(struct Student students[], int numStudents, float average) {
    printf("\nStudents scoring above average:\n");
    for (int i = 0; i < numStudents; i++) {
        if (students[i].marks > average) {
            printf("%s: %d\n", students[i].name, students[i].marks);
        }
    }

    printf("\nStudents scoring below or equal to average:\n");
    for (int i = 0; i < numStudents; i++) {
        if (students[i].marks <= average) {
            printf("%s: %d\n", students[i].name, students[i].marks);
        }
    }
}

int main() {
    int numStudents;

    printf("Enter the number of students: ");
    scanf("%d", &numStudents);

    // Dynamically allocate memory for an array of students
    struct Student *students = (struct Student*)malloc(numStudents * sizeof(struct Student));

    for (int i = 0; i < numStudents; i++) {
        printf("\nEnter details for student %d:\n", i + 1);
        printf("Name: ");
        scanf("%s", students[i].name);
        printf("Marks: ");
        scanf("%d", &students[i].marks);
    }

    float average = computeAverage(students, numStudents);

    printf("\nAverage marks: %.2f\n", average);

    displayAboveBelowAverage(students, numStudents, average);

    free(students);

    return 0;
}

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer