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

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf