-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab1_4.c
39 lines (38 loc) · 1.01 KB
/
Lab1_4.c
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
#include <stdio.h>
struct std {
char name[50];
char id[30];
float cg;
};
int main() {
int n,i,j;
float max,*q;
printf("Number of students: ");
scanf("%d",&n);
struct std *s;
s =(struct std*)malloc(n*sizeof(struct std));//acting as an array of structure
for (i = 0; i < n; i++) {
printf("Information of student %d:",i+1);
printf("\n");
//name,id are already in an array so we didn'nt use &
scanf("%s %s %f",s[i].name,s[i].id,&s[i].cg);
//scanf("Name: %s ID: %s CGPA: %f",(s+i).name,(s+i).id,(s+i).cg);
//Above scanf will not work since we can only write format specifier in scanf
}
max = s[0].cg;
q = &max;
for(i=1;i<n;i++){
if(*q < s[i].cg){
*q = s[i].cg;
j = i;
}
}
printf("The person with the highest CGPA is: %s",s[j].name);
return 0;
}
<!DOCTYPE html>
<html>
<body>
<h2>Project Done by © Nushrat Jaben Aurnima. All Rights Reserved .</h2>
</body>
</html>