-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent_Management.c
More file actions
152 lines (136 loc) · 4.1 KB
/
Student_Management.c
File metadata and controls
152 lines (136 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct students{
char name[20];
int phy_marks;
int chem_marks;
int maths_marks;
int bio_marks;
};
void clearInputBuffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF) { }
}
void stripNewline(char *str) {
size_t len = strlen(str);
if (len > 0 && str[len-1] == '\n') {
str[len-1] = '\0';
}
}
void gradesys(float avg){
if(avg>90 && avg<=100){
printf("Student got grade 'O'\n");
}
else if(avg>80 && avg<=90){
printf("Student got grade 'A'\n");
}
else if(avg>70 && avg<=80){
printf("Student got grade 'B'\n");
}
else if(avg>60 && avg<=70){
printf("Student got grade 'C'\n");
}
else if(avg>50 && avg<=60){
printf("Student got grade 'D'\n");
}
else if(avg>40 && avg<=50){
printf("Student got grade 'E'\n");
}
else{
printf("Student failed in the exam\n");
}
}
int main(){
printf("Welcome to the STUDENT GRADE MANAGEMENT system\n\n");
int num;
printf("Enter the number of students:");
scanf("%d",&num);
clearInputBuffer();
struct students array[num];
for(int i=0;i<num;i++){
printf("Enter the name of student %d:",i+1);
fgets(array[i].name,sizeof(array[i].name),stdin);
stripNewline(array[i].name);
printf("Enter the Physics marks:");
scanf("%d",&array[i].phy_marks);
printf("Enter the Chemistry marks:");
scanf("%d",&array[i].chem_marks);
printf("Enter the Math marks:");
scanf("%d",&array[i].maths_marks);
printf("Enter the Biology marks:");
scanf("%d",&array[i].bio_marks);
printf("\n");
printf("'%s':\n",array[i].name);
float avg = (array[i].phy_marks+array[i].maths_marks+array[i].bio_marks+array[i].chem_marks)/4.0;
printf("The average marks of the student: %.2f\n",avg);
int max = array[i].phy_marks;
if(max < array[i].chem_marks){
max = array[i].chem_marks;
}
if(max < array[i].bio_marks){
max = array[i].bio_marks;
}
if(max < array[i].maths_marks){
max = array[i].maths_marks;
}
int min = array[i].phy_marks;
if(min > array[i].chem_marks){
min = array[i].chem_marks;
}
if(min > array[i].bio_marks){
min = array[i].bio_marks;
}
if(min > array[i].maths_marks){
min = array[i].maths_marks;
}
printf("Maximum marks: %d\nMinimum marks: %d\n", max, min);
gradesys(avg);
printf("\n\n");
clearInputBuffer();
}
int max, count;
printf("In Physics:\n");
max = array[0].phy_marks;
count = 0;
for(int i = 1; i < num; i++){
if(max < array[i].phy_marks){
max = array[i].phy_marks;
count = i;
}
}
printf("%s got maximum %d marks in Physics\n", array[count].name, array[count].phy_marks);
printf("In Chemistry:\n");
max = array[0].chem_marks;
count = 0;
for(int i = 1; i < num; i++){
if(max < array[i].chem_marks){
max = array[i].chem_marks;
count = i;
}
}
printf("%s got maximum %d marks in Chemistry\n", array[count].name, array[count].chem_marks);
printf("In Maths:\n");
max = array[0].maths_marks;
count = 0;
for(int i = 1; i < num; i++){
if(max < array[i].maths_marks){
max = array[i].maths_marks;
count = i;
}
}
printf("%s got maximum %d marks in Mathematics\n", array[count].name, array[count].maths_marks);
printf("In Biology:\n");
max = array[0].bio_marks;
count = 0;
for(int i = 1; i < num; i++){
if(max < array[i].bio_marks){
max = array[i].bio_marks;
count = i;
}
}
printf("%s got maximum %d marks in Biology\n", array[count].name, array[count].bio_marks);
printf("\n\n");
printf("Thank You for using my STUDENT GRADE MANAGEMENT system......I hope it performed well without any bugs in your work\n\n");
return 0;
}