-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudent-info.c
87 lines (76 loc) · 2.94 KB
/
student-info.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
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
# include<stdio.h>
# include<stdlib.h>
typedef struct
{
int marks[5];
char name[30];
int avg;
int d_birth;
int m_birth;
int y_birth;
int age;
int standard;
} STUD;
STUD student_1;
void gen_info();
void marks_avg();
void dob();
void main()
{
printf("Welcome to student portal..\n\n");
gen_info();
}
void gen_info()
{
char *ptr;
ptr = student_1.name;
printf(">> Enter student name: ");
fgets(ptr, 30, stdin);
printf(" $ Student name: %s", student_1.name);
ptr = NULL;
printf(">> Enter student marks: ");
marks_avg();
free(ptr);
dob();
printf(">> Enter student standard: ");
scanf("%d", &student_1.standard);
printf(" $ Student standard: Class-%d", student_1.standard);
}
void marks_avg()
{
int *ptr;
int sum = 0;
int avg = 0;
ptr = (int*) calloc(4, 5);
ptr = student_1.marks;
for (int i = 0; i < 5; i++)
{
scanf("%d", ptr+i);
}
for (int i = 0; i < 5; i++)
{
sum += *(ptr+i);
}
student_1.avg = sum/5;
printf(" $ Student average marks: %d\n", student_1.avg);
}
void dob()
{
printf(">> Enter student D.O.B: ");
scanf("%d/%d/%d", &student_1.d_birth, &student_1.m_birth, &student_1.y_birth);
printf(" $ Student D.O.B entered: %d/%d/%d\n", student_1.d_birth, student_1.m_birth, student_1.y_birth);
student_1.age = 2021 - student_1.y_birth;
printf(" $ Student current age: %d\n", student_1.age);
}
/* Output
Welcome to student portal..
>> Enter student name: John Doe
$ Student name: John Doe
>> Enter student marks: 34 54 76 87 45
$ Student average marks: 59
>> Enter student D.O.B: 14/09/2008
$ Student D.O.B entered: 14/9/2008
$ Student current age: 13
>> Enter student standard: 10
$ Student standard: Class-10
*/