C Program to Store Information of a Student Using Structure

This program stores the information (name, roll and marks) of a student and displays it on the screen using structures.

In this program, a structure, student is created.

This structure has three members: name (string), roll (integer) and marks (float).

Then, a structure variable s is created to store information and display it on the screen.

Example: Store Information and Display it Using Structure

  1. #include <stdio.h>
  2. struct student
  3. {
  4. char name[50];
  5. int roll;
  6. float marks;
  7. } s;
  8. int main()
  9. {
  10. printf("Enter information:\n");
  11. printf("Enter name: ");
  12. scanf("%s", s.name);
  13. printf("Enter roll number: ");
  14. scanf("%d", &s.roll);
  15. printf("Enter marks: ");
  16. scanf("%f", &s.marks);
  17. printf("Displaying Information:\n");
  18. printf("Name: ");
  19. puts(s.name);
  20. printf("Roll number: %d\n",s.roll);
  21. printf("Marks: %.1f\n", s.marks);
  22. return 0;
  23. }

Output

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