We use a special datatype called structure to store data of the students and access the members anywhere with s[i].variable .
Code:
#include<stdio.h>
struct students{
char name[20];
int rollNo;
int age;
}stu[5];
int main(){
printf("Enter the information of students");
for(int i = 0;i<5;i++){
printf("\nEnter the information of roll no %d\n",i+1);
stu[i].rollNo = i+1;
printf("Enter Name of student: ");
scanf("%s",stu[i].name);
printf("\nEnter age of the student: ");
scanf("%d",&stu[i].age);
}
printf("Roll no \t Name \t\t Age\n");
for(int i =0; i<10;i++){
printf("=======");
}
for(int i = 0;i<5;i++){
printf("\n%d \t\t %s \t\t %d",stu[i].rollNo,stu[i].name,stu[i].age);
}
}{codeBox}
This is the C program to store details of 5 students using structure.
Also Read: