Skip to main content

C Program to input and display details of students using structure

 C Program to input and display details of students using structure. 

    In this example, we will enter the details of students like roll number, name and total marks using structure and will be displayed. The total number of student should be entered according to the requirements of the user(maximum value is 50). We can increase the maximum number by changing the statement struct student[50]; to struct student[100];

    Here in the output we have entered details of four student and displayed them accordingly.


PROGRAM

#include<stdio.h>
#include<conio.h>
struct student
{
    int roll;
    char name[20];
    int total;
};
void main()
{
    int i,n;
    struct student std[50];
    printf("Enter the number of students :");
    scanf("%d",&n);
    printf("\nEnter the Students Details.\n");
    for(i=0;i<n;i++)
    {
        printf("Enter Roll Number : ");
        scanf("%d",&std[i].roll);
        printf("Enter Name : ");
        scanf("%s",&std[i].name);
        printf("Enter total : ");
        scanf("%d",&std[i].total);
    }
    printf("\nDisplaying the Student Details.\n");
    printf("Roll Number\tName\tTotal\n");
    for(i=0;i<n;i++)
    {
        printf("     %d\t\t%s\t   %d\n",std[i].roll,std[i].name,std[i].total);
    }
    getch();
}


OUTPUT

Enter the number of students :4


Enter the Students Details.

Enter Roll Number : 1

Enter Name : Jack

Enter total : 98

Enter Roll Number : 2

Enter Name : Lisa

Enter total : 87

Enter Roll Number : 3

Enter Name : Marie

Enter total : 93

Enter Roll Number : 4

Enter Name : Steve

Enter total : 76


Displaying the Student Details.

Roll Number     Name    Total  

     1                Jack       98  

     2                Lisa       87  

     3                Marie      93  

     4                Steve      76  


NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

You Learn, I Learn together We Learn.

Comments