Student Database Manager
C
Easy
3 views
Problem Description
Make the structure of the student (roll_no, name, marks). Create an array of 5 students. Create Functions: addStudent(), displayAll(), findTopScorer(), calculateClassAverage(). Poor mini-project.
Official Solution
#include <stdio.h>
#define SIZE 5
// Structure definition
struct student {
int roll_no;
char name[50];
float marks;
};
// Function to add student details
void addStudent(struct student s[]) {
int i;
for (i = 0; i < SIZE; i++) {
printf("nEnter details of student %dn", i + 1);
printf("Roll Number: ");
scanf("%d", &s[i].roll_no);
printf("Name: ");
scanf("%s", s[i].name);
printf("Marks: ");
scanf("%f", &s[i].marks);
}
}
// Function to display all students
void displayAll(struct student s[]) {
int i;
printf("n--- Student Details ---n");
for (i = 0; i < SIZE; i++) {
printf("nRoll No: %d", s[i].roll_no);
printf("nName: %s", s[i].name);
printf("nMarks: %.2fn", s[i].marks);
}
}
// Function to find top scorer
void findTopScorer(struct student s[]) {
int i, topIndex = 0;
for (i = 1; i < SIZE; i++) {
if (s[i].marks > s[topIndex].marks) {
topIndex = i;
}
}
printf("n--- Top Scorer ---n");
printf("Roll No: %d", s[topIndex].roll_no);
printf("nName: %s", s[topIndex].name);
printf("nMarks: %.2fn", s[topIndex].marks);
}
// Function to calculate class average
void calculateClassAverage(struct student s[]) {
int i;
float sum = 0, average;
for (i = 0; i < SIZE; i++) {
sum += s[i].marks;
}
average = sum / SIZE;
printf("nClass Average Marks: %.2fn", average);
}
// Main function
int main() {
struct student students[SIZE];
addStudent(students);
displayAll(students);
findTopScorer(students);
calculateClassAverage(students);
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!