Summary: This C program stores details of six students using a structure and calculates statistical data such as the minimum, maximum, and average marks. It also determines the student with the highest marks (topper).
#include <stdio.h>
#include <float.h> // For FLT_MIN and FLT_MAX
// Define the student structure
struct student {
char name[50];
char rollNumber[20];
float marks;
};
int main() {
// Initialize data for 6 students
struct student students[6] = {
{"Kandisa Vinay Vishnu Vardhan", "CL20250315011037946", 85.5},
{"Matta Sai Venkat Poojith", "CL2025031501103341", 90.0},
{"Mohammed Abdul Khayyum", "CL2025031501103352", 78.0},
{"Mohammed Faizan Bin Haque", "CL2025031501103363", 88.5},
{"N. Deepika", "CL2025031501103385", 92.0},
{"Nukapeyyi Tanuja", "CL2025031501103374", 80.0}
};
float min = FLT_MAX, max = FLT_MIN, sum = 0;
int topperIndex = 0;
// Display student details and compute stats
printf("Student Details:\n");
for (int i = 0; i < 6; i++) {
printf("Name: %s\n", students[i].name);
printf("Roll Number: %s\n", students[i].rollNumber);
printf("Marks: %.2f\n\n", students[i].marks);
if (students[i].marks < min) {
min = students[i].marks;
}
if (students[i].marks > max) {
max = students[i].marks;
topperIndex = i; // Track topper
}
sum += students[i].marks;
}
float average = sum / 6;
printf("Minimum marks: %.2f\n", min);
printf("Maximum marks: %.2f\n", max);
printf("Average marks: %.2f\n\n", average);
// Print topper details
printf("Topper:\n");
printf("Name: %s\n", students[topperIndex].name);
printf("Roll Number: %s\n", students[topperIndex].rollNumber);
return 0;
}
Structures:
The program uses a struct
named student
to group related data (name, roll number, and marks) together. This enables the storage and management of multiple student records as a single array of structured data.
Array of Structures:
An array students[6]
is used to store six records. This makes iteration and data access straightforward using indexing.
Preprocessor Directives:
#include <float.h>
is used to include constants like FLT_MAX
and FLT_MIN
, which provide the initial extreme values for finding min/max marks.
Looping through Arrays:
A for
loop iterates over all student records to print data, calculate the sum of marks, and track minimum, maximum, and topper information.
Conditional Logic:
The program uses if
statements to update min
, max
, and topperIndex
during the iteration. This helps track important statistical values efficiently.
Float Arithmetic:
Floating-point variables are used to represent marks and compute averages. The format specifier %.2f
ensures output is rounded to two decimal places.
Index Tracking:
topperIndex
stores the index of the student with the highest marks, enabling easy access to their details at the end of the program.