C Example for Beginners: C Program to Store Information of a Student Using Structure

(C programming Example for Beginners)

C Program to Store Information of a Student Using Structure

In this example, you will learn to store the information of a student in a structure and display them on the screen.


Store Information and Display it Using Structure


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

int main(){
    printf("Enter information:n");
    printf("Enter name: ");
    fgets(s.name, sizeof(s.name), stdin);

    printf("Enter roll number: ");
    scanf("%d", &s.roll);
    printf("Enter marks: ");
    scanf("%f", &s.marks);

    printf("Displaying Information:n");
    printf("Name: ");
    printf("%s", s.name);
    printf("Roll number: %dn", s.roll);
    printf("Marks: %.1fn", s.marks);

    return 0;
}

Output

Enter information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Displaying Information:
Name: Jack
Roll number: 23
Marks: 34.5

In this program, a structure student is created. The structure has three members: name (string), roll (integer) and marks (float).

C Example for Beginners: C Program to Store Information of a Student Using Structure

Sign up to get end-to-end “Learn By Coding” example.



Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.