Create structure and display elements - C

Write a C-program to create student structure having field roll_no, stud_name, class. Pass this entire structure to function and display the structure elements.

Solution:

#include<stdio.h>
struct stud
{
     int roll_no;
     char stud_name[20];
     int std;
}s;
void student(struct stud s)
{
     printf("Student details:\n");
     printf("--------------------------\n");
     printf("Roll Number : %d",s.roll_no);
     printf("\nName        : %s",s.stud_name);
     printf("\nStd         : %d",s.std);
}
int main()
{
     printf("Enter Student Details\n");
     printf("--------------------------\n");
     printf("Roll Number : ");
     scanf("%d",&s.roll_no);
     printf("Name        : ");
     scanf("%s",s.stud_name);
     printf("Std.        : ");
     scanf("%d",&s.std);
     printf("--------------------------\n");
     student(s);
     return 0;
}


Output:

student structure