how to store a student data in struct in c

Solutions on MaxInterview for how to store a student data in struct in c by the best coders in the world

showing results for - "how to store a student data in struct in c"
Matys
24 Aug 2018
1#include <stdio.h>
2struct student {
3    char firstName[50];
4    int roll;
5    float marks;
6} s[10];
7
8int main() {
9    int i;
10    printf("Enter information of students:\n");
11
12    // storing information
13    for (i = 0; i < 5; ++i) {
14        s[i].roll = i + 1;
15        printf("\nFor roll number%d,\n", s[i].roll);
16        printf("Enter first name: ");
17        scanf("%s", s[i].firstName);
18        printf("Enter marks: ");
19        scanf("%f", &s[i].marks);
20    }
21    printf("Displaying Information:\n\n");
22
23    // displaying information
24    for (i = 0; i < 5; ++i) {
25        printf("\nRoll number: %d\n", i + 1);
26        printf("First name: ");
27        puts(s[i].firstName);
28        printf("Marks: %.1f", s[i].marks);
29        printf("\n");
30    }
31    return 0;
32}
33