-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentDetails.c
65 lines (56 loc) · 1.75 KB
/
StudentDetails.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
//Write a program in C to create an array of structure type. Define the structure student with members name, roll, marks.
//Write 2 functions: 1. to take input into each element of the array. 2. to display the individual elements of the array using pointers.
#include<stdio.h>
#include<stdlib.h>
struct Student {
char name[100];
int roll;
float marks;
};
void input(struct Student *ptr, int n);
void display(struct Student *ptr, int n);
int main() {
struct Student s[100];
struct Student *ptr = s;
int ch, n;
printf("Enter the number of students: ");
scanf("%d", &n);
while (1) {
printf("Enter 1 to input details, 2 to display details, and 3 to exit: ");
scanf("%d", &ch);
switch (ch) {
case 1:
input(ptr, n);
break;
case 2:
display(ptr, n);
break;
case 3:
exit(0);
break;
default:
printf("Invalid Input\n");
break;
}
}
return 0;
}
void input(struct Student *ptr, int n) {
for (int i = 0; i < n; i++) {
printf("\nEnter details of Student %d\n", i + 1);
printf("Enter name: ");
scanf("%s", (ptr + i)->name);
printf("Enter roll: ");
scanf("%d", &(ptr + i)->roll);
printf("Enter marks: ");
scanf("%f", &(ptr + i)->marks);
}
}
void display(struct Student *ptr, int n) {
for (int i = 0; i < n; i++) {
printf("\nDetails of Student %d\n", i + 1);
printf("Name: %s\n", (ptr + i)->name);
printf("Roll: %d\n", (ptr + i)->roll);
printf("Marks: %.2f\n", (ptr + i)->marks);
}
}