Write a program to get the details of n students and to display their details in the given order.


Create a structure called Student.
struct Student
{
char name[30];
char department[20];
int yearOfStudy;
float cgpa;
};


Implementation of the above problem:
#include<stdio.h>
int main()
{
struct Student
{
char name[30];
char department[20];
int yearOfStudy;
float cgpa;
};
int n,i,j;
printf("Enter the number of students\n");
scanf("%d",&n);
struct Student stud[n];
j=1;
for(i=0;i<n;i++)
{   
printf("Enter the details of student %d\n",j);
printf("Enter name\n");
scanf("%s",stud[i].name);
printf("Enter department\n");
scanf("%s",stud[i].department);
printf("Enter year of study\n");
scanf("%d",&stud[i].yearOfStudy);
printf("Enter cgpa\n");
scanf("%f",&stud[i].cgpa);
j++; 
}
printf("Details of students\n");
j=1;
for(i=0;i<n;i++)
{   

printf("Student %d\n",j);
printf("Name : %s\n",stud[i].name);
printf("Department : %s\n",stud[i].department);
printf("Year of study : %d\n",stud[i].yearOfStudy);
printf("CGPA : %.2f\n",stud[i].cgpa);
 j++;
}
return 0;
}



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:

  1. struct College
    {
    char name[100];
    char department[100];
    int establishmentYear;
    float passPercentage;
    };

    ReplyDelete