#include #include #define MAX_STUDENTS 3 #define MAX_NAME_LEN 50 struct Student { char name[MAX_NAME_LEN]; float marks[3]; }; void calculate(const struct Student* s, float* total, float* average) { *total = s->marks[0] + s->marks[1] + s->marks[2]; *average = *total / 3.0f; } void getMention(float avg, char* mention, size_t mSize, char* result, size_t rSize) { if (avg >= 17.0f) { strcpy_s(mention, mSize, "Excellent"); strcpy_s(result, rSize, "PASS"); } else if (avg >= 14.0f) { strcpy_s(mention, mSize, "Very Good"); strcpy_s(result, rSize, "PASS"); } else if (avg >= 12.0f) { strcpy_s(mention, mSize, "Good"); strcpy_s(result, rSize, "PASS"); } else if (avg >= 10.0f) { strcpy_s(mention, mSize, "Pass"); strcpy_s(result, rSize, "PASS"); } else { strcpy_s(mention, mSize, "Fail"); strcpy_s(result, rSize, "FAIL"); } } void displayRow(const struct Student* s, float total, float avg, const char* result, const char* mention) { printf("| %-10s | %5.2f | %5.2f | %5.2f | %6.2f | %5.2f | %-6s | %-10s |\n", s->name, s->marks[0], s->marks[1], s->marks[2], total, avg, result, mention); } void displayAll(struct Student s[], int index, int size) { if (index == size) return; float total, avg; char mention[20], result[10]; calculate(&s[index], &total, &avg); getMention(avg, mention, sizeof(mention), result, sizeof(result)); displayRow(&s[index], total, avg, result, mention); displayAll(s, index + 1, size); } int main(void) { struct Student students[MAX_STUDENTS]; for (int i = 0; i < MAX_STUDENTS; i++) { printf("Enter name for student %d: ", i + 1); // scanf_s needs buffer size as unsigned int scanf_s("%49s", students[i].name, (unsigned int)MAX_NAME_LEN); for (int j = 0; j < 3; j++) { printf("Enter mark %d (out of 20): ", j + 1); scanf_s("%f", &students[i].marks[j]); } printf("\n"); } printf("\n| %-10s | %-5s | %-5s | %-5s | %-6s | %-5s | %-6s | %-10s |\n", "Name", "M1", "M2", "M3", "Total", "Avg", "Result", "Mention"); printf("|------------|-------|-------|-------|--------|-------|--------|------------|\n"); displayAll(students, 0, MAX_STUDENTS); printf("\nPress Enter to exit..."); getchar(); // consume trailing newline getchar(); // wait for user return 0; }