Summary: This C program stores the details of six students using structures, calculates the minimum, maximum, and average marks, and displays all student information along with the statistics.
#include <stdio.h>
#include <float.h> // Include float.h for FLT_MAX and FLT_MIN
int main() {
struct student {
char name[50];
char rollNumber[20];
float marks;
};
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;
float max = FLT_MIN;
float sum = 0;
for (int i = 0; i < 6; i++) {
if (students[i].marks < min) {
min = students[i].marks;
}
if (students[i].marks > max) {
max = students[i].marks;
}
sum += students[i].marks;
}
printf("\nStudent 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);
}
printf("Minimum marks: %.2f\n", min);
printf("Maximum marks: %.2f\n", max);
printf("Average marks: %.2f\n", sum / 6);
return 0;
}
Structures:
The program uses a struct
to define a custom data type called student
, which groups together multiple variables: name, roll number, and marks. This allows the program to treat each student's details as a single entity.
Arrays of Structures:
An array students[6]
holds the data of six students. Each element in the array is a structure variable, enabling easy iteration and access to student details.
Initialization:
The array is initialized with predefined data for each student. This allows the program to operate without additional user input.
Using <float.h>:
Constants FLT_MAX
and FLT_MIN
from the <float.h>
library are used to initialize min
and max
respectively. These provide safe starting values when searching for minimum and maximum marks.
Loops and Aggregation:
A for
loop iterates over the array to:
for
loop prints each student's details.
Formatted Output:
The program uses printf()
with format specifiers like %.2f
to neatly display float values up to two decimal places.