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 convert a given temperature value from Fahrenheit to Centigrade and vice versa?

  Write a C program to convert a given temperature value from Fahrenheit to Centigrade and vice versa?          In this example we will learn how to convert a given temperature in Fahrenheit to Centigrade and to convert given  temperature value from Centigrade to Fahrenheit depending on the choice of the user.                To solve this program we should have basic knowledge in c and most importantly a clear concept on : Switch Statement             And we must know the formula of conversion from Fahrenheit to Centigrade(Celsius) and Centigrade(Celsius) to Fahrenheit. Fahrenheit To Centigrade Centigrade To Fahrenheit PROGRAM       #include <stdio.h> #include <conio.h> void   main () {      float   f , c ;      int   ch ;      printf ( "CONVERT" );      printf ( " \n 1. Fahrenheit to Celsius." );      printf ( " \n 2. Celsius to Fahrenheit \n " );      printf ( " \n Enter your choice (1|2):" );      sca

C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.

  C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a   circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.     To define a Circle class in C++, we start by declaring the class with the class keyword, followed by the name of the class. In this case, we'll call it Circle . We'll then define a private data member to store the radius of the circle. Here's the code to do that:    class Circle {      private:      double radius;    };          Next, we need to define public member functions that can set and get the value of the radius, as well as calculate the area and perimeter of the circle. Here's the full code for the Circle class: class Circle { private: double radius; public: void setRadius(double r) { radius = r; } double getRadius() { return radius; } double area() { return 3.14159 * r