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 find out the roots of a Quadratic Equation and also test for Real and Complex roots

 C Program to find out the roots of a Quadratic Equation  and also test for Real and Complex roots.       In this example, we will calculate the roots of the quadratic equation by testing for real and complex roots. We can test real and complex roots by checking these conditions : If b 2  −4 ac  < 0, then there are no real roots. If b 2  −4 ac  = 0, then both the roots are equal. If b 2  −4 ac  > 0, then roots are real and distinct.   PROGRAM TO FIND OUT THE ROOTS OF A QUADRATIC EQUATION. #include <stdio.h> #include <conio.h> #include <math.h> int   main () {      int   a , b , c , d ;      float   x , y ;      printf ( "Enter coefficient of x^2,x and constant : " );      scanf ( " %d   %d   %d " ,& a ,& b ,& c );      d = b * b ...

C Program to find the sum of the series 1^2+2^2+3^2+…..+n^2

C Program to find the sum of the series  1 2 +2 2 +3 2 +…..+n 2 Enter the end limit at the runtime.       In this example, we calculate the sum of the above mentioned series till the end-limit entered by the user. We have used built-in function pow(x,y) to find the power of the given number.     Here in the output we have entered the value of end-limit as number 7 which gives a sum of 140.    PROGRAM #include <stdio.h> #include <math.h> #include <conio.h> void   main () {      int  n,sum= 0 ,i;      printf ( "Enter the end limit :" );      scanf ( " %d " ,&n);      for (i= 1 ;i<=n;i++)     {         sum=sum+ pow (i, 2 );     }      printf ( "Sum of the series is :  %d " ,sum);  ...

C Program to Generate Multiplication Table according to User Choice.

 C Program to Generate Multiplication Table according to User Choice.     In this program, we will learn how to print a multiplication table according to any positive number entered by the user. This program uses for loop to solve this problem.  C PROGRAM TO GENERATE MULTIPLICATION TABLE: # include < stdio.h > # include < conio.h > int   main () {      int   i , num , res = 0 ;      printf ( "\n Enter the multplication table you want :  " );      scanf ( " %d " ,& num );      printf ( "\n\n\n\t MULTIPLICATION TABLE OF  %d \t" , num );      printf ( "\n -------------------------------------------------- \n" );      for ( i = 1 ; i <= 10 ; i ++)      {          res = num * i ;       ...

C Program to Generate and Print Fibonacci series upto a given inputted number

 C Program to Generate and Print Fibonacci series upto a given inputted number     In this example, we will generate and print fibonacci series upto a the upper limit entered by the user. To solve this problem we should have a proper concept on Fibonacci series and while loop.  What is a Fibonacci Series? Fibonacci series is the sum of the two preceding numbers, starting from 0 and 1.     For Example: 0,1,1,2,3,5,8,13,....,etc  PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   n , x1 , x2 , x3 = 0 ;      printf ( "Enter the limit upto which fibonacci series to be generated : " );      scanf ( " %d " ,& n );      x1 = 0 ;      x2 = 1 ;      printf ( " %d \t %d " , x1 , x2 );      x3 = x1 + x2 ;   ...