c program to store student information using structure

In this example, we will store student information using structure.

Store Information of a Student Using Structure

#include <stdio.h>
struct student
    char name[50];
    int roll;
    float marks;
} s[100];

int main()
    int i,n;
    struct student s[100];

    printf("Enter total of students:");

        printf("\n Enter information of student %d:\n",i+1);
        printf("Enter name: ");
        scanf("%s", s[i].name);

        printf("Enter roll number: ");
        scanf("%d", &s[i].roll);

        printf("Enter marks: ");
        scanf("%f", &s[i].marks);

    printf("Displaying Information:\n");
        printf("\n %d no. student info\n",i+1);
        printf("\t Name:%s\n ",s[i].name);
        printf("\t Roll number: %d\n",s[i].roll);
        printf("\t Marks: %.1f\n\n",s[i].marks);

    return 0;

Output :

Enter total of students:2

Enter information of student 1:
Enter name: John
Enter roll number: 1
Enter marks: 88

Enter information of student 2:
Enter name: Louis
Enter roll number: 95
Enter marks: 85
Displaying Information:

    1 no. student info
        Roll number: 1
        Marks: 88.0

    2 no. student info
        Roll number: 95
        Marks: 85.0

Share your thoughts

Ask anything about this examples