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
struct College
ReplyDelete{
char name[100];
char department[100];
int establishmentYear;
float passPercentage;
};